示例#1
0
        public void UpdateSovausers()
        {
            DateTime now      = DateTime.Now;
            var      sovaUser = new SovaUser {
                SovaUserCreationDate = now
            };
            var options = new DbContextOptionsBuilder <SovaContext>()
                          .UseInMemoryDatabase(databaseName: "UpdateSovausers")
                          .Options;

            using (var context = new SovaContext(options))
            {
                var service = new SovaUserDataService(context);
                service.Add(sovaUser);
                now = DateTime.Now;
                sovaUser.SovaUserCreationDate = DateTime.Now;

                service.Update(sovaUser);
            }

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new SovaContext(options))
            {
                Assert.Equal(now, context.SovaUsers.Single().SovaUserCreationDate);
            }
        }
示例#2
0
        public void Remove_sovausers_from_database()
        {
            DateTime now      = DateTime.Now;
            var      sovaUser = new SovaUser {
                SovaUserCreationDate = now
            };
            var options = new DbContextOptionsBuilder <SovaContext>()
                          .UseInMemoryDatabase(databaseName: "RemoveSovausersFromDatabase")
                          .Options;

            // Run the test against one instance of the context
            using (var context = new SovaContext(options))
            {
                var service = new SovaUserDataService(context);
                service.Add(sovaUser);
                service.Add(sovaUser);
                service.Delete(1);
            }

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new SovaContext(options))
            {
                Assert.Equal(2, context.SovaUsers.Single().SovaUserId);
                Assert.Equal(1, context.SovaUsers.Count());
            }
        }
示例#3
0
        public void GetSingleSovauser()
        {
            DateTime now = DateTime.Now;
            SovaUser retrievedSovaUser;
            SovaUser sovaUser = new SovaUser {
                SovaUserCreationDate = now
            };
            var options = new DbContextOptionsBuilder <SovaContext>()
                          .UseInMemoryDatabase(databaseName: "GetSingleSovauser")
                          .Options;

            using (var context = new SovaContext(options))
            {
                var service = new SovaUserDataService(context);
                service.Add(sovaUser);
                retrievedSovaUser = service.Get(1);
            }

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new SovaContext(options))
            {
                Assert.NotNull(retrievedSovaUser);
                Assert.Equal(sovaUser.SovaUserCreationDate, context.SovaUsers.Single().SovaUserCreationDate);
            }
        }
示例#4
0
 public static SovaUserModel Map(SovaUser sovaUser, IUrlHelper url)
 {
     return(new SovaUserModel
     {
         Url = url.Link(Config.SovaUserRoute, new { id = sovaUser.SovaUserId }),
         SovaUserId = sovaUser.SovaUserId,
         SovaUserCreationDate = sovaUser.SovaUserCreationDate
     });
 }
示例#5
0
        public void GetListOfSovaUsers()
        {
            DateTime         now = DateTime.Now;
            int              AmountOfRetrievedSovaUsers = 5;
            IList <SovaUser> retrievedSovaUser;
            SovaUser         sovaUser = new SovaUser {
                SovaUserCreationDate = now
            };
            var options = new DbContextOptionsBuilder <SovaContext>()
                          .UseInMemoryDatabase(databaseName: "GetListOfSovausers")
                          .Options;

            using (var context = new SovaContext(options))
            {
                var service = new SovaUserDataService(context);
                service.Add(sovaUser);
                now = DateTime.Now;
                service.Add(sovaUser);
                now = DateTime.Now;
                service.Add(sovaUser);
                now = DateTime.Now;
                service.Add(sovaUser);
                now = DateTime.Now;
                service.Add(sovaUser);
                retrievedSovaUser = service.GetList(0, AmountOfRetrievedSovaUsers);
            }

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new SovaContext(options))
            {
                Assert.NotNull(retrievedSovaUser);
                Assert.NotEmpty(retrievedSovaUser);
                Assert.IsType <List <SovaUser> >(retrievedSovaUser);
                Assert.Equal(AmountOfRetrievedSovaUsers, retrievedSovaUser.Count());
            }
        }