Пример #1
0
 public User CreateUser()
 {
     var user = new User();
     using (var ctx = new IPContext())
     {
         ctx.Users.Add(user);
         ctx.SaveChanges();
     }
     return user;
 }
Пример #2
0
 protected void LogToSql(int userId, int organisationId, string applicationName, string message, string data)
 {
     using (var ctx = new IPContext())
     {
         ctx.LogEntries.Add(new LogEntry
         {
             UserId = userId,
             OrganisationId = organisationId,
             ApplicationName = applicationName,
             Message = message,
             Data = data
         });
         ctx.SaveChanges();
     }
 }
Пример #3
0
 public void CreateUser()
 {
     var user = new User()
     {
         //Have to initialize the empty list because otherwise the JSON comparison borks
         //TODO: custom serializer?
         LogEntries = new List<LogEntry>()
     };
     using (var ctx = new IPContext())
     {
         ctx.Users.Add(user);
         ctx.SaveChanges();
     }
     using (var ctx = new IPContext())
     {
         var fromDb = ctx.Users.Find(user.UserId);
         var originalJson = serializer.Serialize(user);
         var fromDbJson = serializer.Serialize(fromDb);
         Assert.IsTrue(CompareJson(originalJson, fromDbJson));
     }
 }
Пример #4
0
 public void CreateLogEntry()
 {
     var logEntry = new LogEntry()
     {
         UserId = 1,
         OrganisationId = 1,
         ApplicationName = "DataAccessTests",
         CreatedAt = new SqlDateTime(DateTime.Now).Value,
         Message = "Test message",
         Data = Environment.StackTrace
     };
     using (var ctx = new IPContext())
     {
         ctx.LogEntries.Add(logEntry);
         ctx.SaveChanges();
     }
     using (var ctx = new IPContext())
     {
         var fromDb = ctx.LogEntries.Find(logEntry.ID);
         var originalJson = serializer.Serialize(logEntry);
         var fromDbJson = serializer.Serialize(fromDb);
         Assert.AreEqual(originalJson, fromDbJson);
     }
 }