Exemple #1
0
        public void RegisterTest()
        {
            var          authentication = new Authentication(new InMemoryDbContextFactory());
            const string password       = "******";

            var user = new UserDetailModel()
            {
                Email     = "*****@*****.**",
                FirstName = "David",
                LastName  = "Endrych",
                Nickname  = "david",
                Password  = password,
            };

            var newUser = authentication.Registration(user);

            Assert.NotEqual(Guid.Empty, newUser.Id);
            Assert.NotNull(newUser.Salt);
            Assert.NotEqual(newUser.Password, password);

            using (var context = new InMemoryDbContextFactory().CreateDbContext())
            {
                var databaseUser = context.Users.FirstOrDefault(u => u.Id == newUser.Id);
                Assert.NotNull(databaseUser);
                Assert.Equal(newUser.Email, databaseUser.Email);
                Assert.Equal(newUser.Password, databaseUser.Password);
                Assert.Equal(newUser.FirstName, databaseUser.FirstName);
                Assert.Equal(newUser.LastName, databaseUser.LastName);
            }
        }
        public void SavePostButNotFoundTest()
        {
            var dbContextFactory = new InMemoryDbContextFactory();

            const string content = "Test1";

            using (var context = dbContextFactory.CreateDbContext())
            {
                context.Posts.Add(new PostEntity()
                {
                    Content = content, Timestamp = DateTime.Now
                });
                context.SaveChanges();
                var postFromDatabase = context.Posts.FirstOrDefault(post => post.Content == "42");
                Assert.Null(postFromDatabase);
            }
        }