Skip to content

Commit

Permalink
Merge pull request #13 from Moesif/add-apim-users
Browse files Browse the repository at this point in the history
Added Apim User. increment version to 2.0.2
  • Loading branch information
dkm199 authored Mar 8, 2021
2 parents ffbdc76 + 98eee15 commit d464910
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 20 deletions.
50 changes: 33 additions & 17 deletions Moesif.Api.Test/ApiControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class ApiControllerTest : ControllerTestBase
{
private static ApiController controller;

private EventModel CreateEvent()
{
private EventModel CreateEvent()
{
// Parameters for the API call
var reqHeaders = new Dictionary<string, string>();
reqHeaders.Add("Host", "api.acmeinc.com");
Expand Down Expand Up @@ -87,9 +87,9 @@ private EventModel CreateEvent()
CompanyId = "67890",
SessionToken = "XXXXXXXXX",
Metadata = metadata
};

return eventModel;
};

return eventModel;
}

[Fact]
Expand Down Expand Up @@ -172,12 +172,12 @@ public async Task TestUpdateUser()
}
};

var campaign = new CampaignModel()
{
UtmSource = "Newsletter",
UtmMedium = "Email"
};

var campaign = new CampaignModel()
{
UtmSource = "Newsletter",
UtmMedium = "Email"
};

var userModel = new UserModel()
{
UserAgentString = "Dalvik/2.1.0 (Linux; U; Android 5.0.2; C6906 Build/14.5.A.0.242)",
Expand Down Expand Up @@ -205,8 +205,8 @@ public async Task TestUpdateUser()
[Fact]
public async Task TestUpdateUsersBatch()
{
Boolean isUpdated = false;
// Parameters for the API call
Boolean isUpdated = false;
// Parameters for the API call
List<UserModel> body = new List<UserModel>();

Dictionary<string, object> metadata = new Dictionary<string, object>
Expand Down Expand Up @@ -272,10 +272,10 @@ public async Task TestUpdateCompany()
}
};

var campaign = new CampaignModel()
{
UtmSource = "Adwords",
UtmMedium = "Twitter"
var campaign = new CampaignModel()
{
UtmSource = "Adwords",
UtmMedium = "Twitter"
};

var companyModel = new CompanyModel()
Expand Down Expand Up @@ -350,5 +350,21 @@ public async Task TestUpdateCompanies()
Assert.Equal(true, isUpdated);

}

[Fact]
public async Task TestContextUserModel()
{
string jStr = @"{
'Id' : 'v1',
'Email' : 'v2',
'FirstName' : 'v3',
'LastName' : 'v4',
}";
ContextUserModel m = ContextUserModel.deserialize(jStr);
Assert.Equal("v1", m.Id);
Assert.Equal("v2", m.Email);
Assert.Equal("v3", m.FirstName);
Assert.Equal("v4", m.LastName);
}
}
}
130 changes: 130 additions & 0 deletions Moesif.Api/Models/ContextUserModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
using System;
using System.ComponentModel;
using Newtonsoft.Json;

namespace Moesif.Api.Models
{
public class ContextModel : INotifyPropertyChanged
{
private ContextUserModel user;

[JsonProperty("user")]
public ContextUserModel User
{
get
{
return this.user;
}
set
{
this.user = value;
onPropertyChanged("User");
}
}

/// <summary>
/// Property changed event for observer pattern
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;

/// <summary>
/// Raises event when a property is changed
/// </summary>
/// <param name="propertyName">Name of the changed property</param>
protected void onPropertyChanged(String propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}

}

public class ContextUserModel : INotifyPropertyChanged
{
private String id;
private String email;
private String firstName;
private String lastName;

[JsonProperty("Id")]
public String Id
{
get
{
return this.id;
}
set
{
this.id = value;
onPropertyChanged("Id");
}
}

[JsonProperty("Email")]
public String Email
{
get
{
return this.email;
}
set
{
this.email = value;
onPropertyChanged("Email");
}
}

[JsonProperty("FirstName")]
public String FirstName
{
get
{
return this.firstName;
}
set
{
this.firstName = value;
onPropertyChanged("FirstName");
}
}
[JsonProperty("LastName")]
public String LastName
{
get
{
return this.lastName;
}
set
{
this.lastName = value;
onPropertyChanged("LastName");
}
}
/// <summary>
/// Property changed event for observer pattern
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;

/// <summary>
/// Raises event when a property is changed
/// </summary>
/// <param name="propertyName">Name of the changed property</param>
protected void onPropertyChanged(String propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}

public static ContextUserModel deserialize(String jsonStr)
{
ContextUserModel m = null;
if (!string.IsNullOrWhiteSpace(jsonStr))
m = JsonConvert.DeserializeObject<ContextUserModel>(jsonStr.Trim());
return m;
}
}
}
18 changes: 18 additions & 0 deletions Moesif.Api/Models/EventModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class EventModel : INotifyPropertyChanged
// These fields hold the values for the public properties.
private EventRequestModel request;
private EventResponseModel response;
private ContextModel context;
private string sessionToken;
private string tags;
private string userId;
Expand Down Expand Up @@ -63,6 +64,23 @@ public EventResponseModel Response
}
}

/// <summary>
/// context.Request.User from Apim policy
/// </summary>
[JsonProperty("context")]
public ContextModel Context
{
get
{
return this.context;
}
set
{
this.context = value;
onPropertyChanged("Context");
}
}

/// <summary>
/// End user's auth/session token
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Moesif.Api/Moesif.Api.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Moesif.Api</id>
<version>2.0.1</version>
<version>2.0.2</version>
<title>MoesifApi</title>
<authors>Moesif</authors>
<owners>Moesif</owners>
Expand Down
4 changes: 2 additions & 2 deletions Moesif.Api/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.1")]
[assembly: AssemblyFileVersion("2.0.1")]
[assembly: AssemblyVersion("2.0.2")]
[assembly: AssemblyFileVersion("2.0.2")]

0 comments on commit d464910

Please sign in to comment.