Hi Demis Sorry for the delay but had some issues to resolved, bellow is a unit test using nunit that shows the prb,
you will see that it will log stating that IMyCustomSession is null and also the IAuthSession, then the test will fail on the Assert.IsNotNull(sess2).
Hope this helps you finding the problem.
Also the Json that is stored under CacheEntry.Data is.
{“userId”:“df26d517-a739-481c-9185-8ecf6c7421ab”,“isLockedOut”:false,“loginAttempts”:0,“userAuthId”:“df26d517-a739-481c-9185-8ecf6c7421ab”,“userAuthName”:“TestUser”,“userName”:“Test User”,“timeZone”:“Eastern Standard Time”,“lastModified”:“2016-03-03T09:25:00.7253692”,“isAuthenticated”:true,“tag”:0,“providerOAuthAccess”:[]}
namespace Millennium.Aws.Tests
{
public interface IMyCustomSession: IAuthSession
{
Guid UserId { get; set; }
bool IsLockedOut { get; set; }
int LoginAttempts { get; set; }
DateTime? LastLoginAttempt { get; set; }
}
[DataContract]
public class MyCustomSession: AuthUserSession, IMyCustomSession
{
[DataMember]
public Guid UserId
{
get
{
return UserAuthId.To<Guid>();
}
set
{
UserAuthId = value.ToString("D");
}
}
[DataMember]
public bool IsLockedOut { get; set; }
[DataMember]
public int LoginAttempts { get; set; }
[DataMember]
public DateTime? LastLoginAttempt { get; set; }
}
[TestFixture]
public class DynamoDbSessionTests
{
private IAppSettings _settings;
private ICacheClient _cacheClient ;
private Funq.Container _container;
[OneTimeSetUp]
public void OneTimeSetUp()
{
var dic = new Dictionary<string, string>
{
{"Cache.Provider", "DynamoDb"},
{"Cache.Key", "AWSKey"},
{"Cache.Secret", "AWSSecret"}
};
_settings = new DictionarySettings(dic);
_container = new Funq.Container();
_container.Register(_settings);
var awsDb = new AmazonDynamoDBClient(_settings.GetString("Cache.Key"),
_settings.GetString("Cache.Secret"),
RegionEndpoint.USEast1);
_cacheClient = new DynamoDbCacheClient(new PocoDynamo(awsDb));
AuthenticateService.CurrentSessionFactory = ()=> new MeevoSession();
_container.Register(_cacheClient);
LogManager.LogFactory = new ConsoleLogFactory();
JsConfig.EmitCamelCaseNames = true;
JsConfig<Guid>.SerializeFn = (guid => guid.ToString("D"));
JsConfig.ThrowOnDeserializationError = false;
JsConfig.TypeWriter = (type) => type.Name;
JsConfig.AppendUtcOffset = false;
JsConfig.IncludeNullValues = false;
JsConfig.TryToParseNumericType = true;
JsConfig.TryToParsePrimitiveTypeValues = true;
JsConfig.TreatEnumAsInteger = true;
JsConfig<DateTime>.SerializeFn =
(date => date.ChangeToUnspecifiedKind().ToString("O"));
JsConfig<DateTime>.DeSerializeFn =
(dateStr => dateStr.ToDateTime());
JsConfig<DateTime?>.SerializeFn =
(date =>
date?.ChangeToUnspecifiedKind().ToString("O") ?? "null");
JsConfig<DateTime?>.DeSerializeFn =
(dateStr =>
string.IsNullOrEmpty(dateStr) ||
string.Equals(dateStr, "null", StringComparison.OrdinalIgnoreCase)
? null as DateTime?
: dateStr.ToDateTimeNullable());
// TimeSpan serialization corresponds with Time of Day component of DateTime round-trip format ("O")
JsConfig<TimeSpan>.SerializeFn =
(time => (time.Ticks < 0 ? "-" : "") + time.ToString("hh':'mm':'ss'.'fffffff"));
JsConfig<TimeSpan>.DeSerializeFn =
(timeString =>
{
bool negate = false;
if (timeString.IndexOf("-", StringComparison.InvariantCulture) == 0)
{
negate = true;
timeString = timeString.Substring(1);
}
TimeSpan time = TimeSpan.ParseExact(timeString, "hh':'mm':'ss'.'fffffff",
CultureInfo.InvariantCulture);
if (negate)
{
time = time.Negate();
}
return time;
});
}
[OneTimeTearDown]
public void OneTimeTearDown()
{
var client = _cacheClient as DynamoDbCacheClient;
client?.Dispose();
}
[Test]
public void SessionTests()
{
var logger = LogManager.GetLogger("SessionTests");
var sessionKey = "urn:iauthsession:VVtJJbBJ0Po4xI6eU1zF";
var session = new MyCustomSession
{
IsAuthenticated = true,
UserId = Guid.NewGuid(),
TimeZone = TimeZoneInfo.Local.Id,
UserAuthName = "TestUser",
UserName = "Test User",
LastModified = DateTime.UtcNow,
};
_cacheClient.CacheSet(sessionKey, session, new TimeSpan(0, 14, 0));
var sess = _cacheClient.Get<MyCustomSession>(sessionKey);
var sess1 = _cacheClient.Get<AuthUserSession>(sessionKey);
var sess2 = _cacheClient.Get<IMyCustomSession>(sessionKey);
var sess3 = _cacheClient.Get<IAuthSession>(sessionKey);
if (sess == null)
{
logger.Warn("Getting MyCustomSession from cache returned null.");
}
if (sess1 == null)
{
logger.Warn("Getting AuthUserSession from cache returned null.");
}
if (sess2 == null)
{
logger.Warn("Getting IMyCustomSession from cache returned null.");
}
if (sess3 == null)
{
logger.Warn("Getting IAuthSession from cache returned null.");
}
Assert.IsNotNull(sess);
Assert.IsNotNull(sess1);
Assert.IsNotNull(sess2);
Assert.IsNotNull(sess3);
}
}
}