Ejemplo n.º 1
0
        public async void TestDeletePetAsync()
        {
            // Arrange
            AppDbContext   appDbContext   = AppDbContextMock.GetAppDbContext();
            PetRepository  petRepository  = new PetRepository(appDbContext);
            UserRepository userRepository = new UserRepository(appDbContext);
            PetService     petService     = new PetService(petRepository, userRepository, new UnitOfWork(appDbContext));

            appDbContext.Users.Add(new User {
                Id = 210, Name = "Jessica"
            });
            appDbContext.Add(new Cat {
                Id = 110, Name = "Mae", UserId = 210
            });
            appDbContext.SaveChangesAsync().Wait();

            // Act
            var petDeleted = await petService.DeleteAsync(110);

            var findPet = await petService.GetAsync(110);

            // Assert
            Assert.NotNull(petDeleted);
            Assert.Equal("Mae", petDeleted.Name);
            Assert.Null(findPet);
        }
Ejemplo n.º 2
0
        public async void TestDegradeMetrics()
        {
            // Arrange
            AppDbContext   appDbContext   = AppDbContextMock.GetAppDbContext();
            PetRepository  petRepository  = new PetRepository(appDbContext);
            UserRepository userRepository = new UserRepository(appDbContext);
            PetService     petService     = new PetService(petRepository, userRepository, new UnitOfWork(appDbContext));

            appDbContext.Users.Add(new User {
                Id = 225, Name = "Noel"
            });
            var happinessAtTimeOfCreation = appDbContext.Add(new Cat {
                Id = 125, Name = "Molly", UserId = 225
            })
                                            .Entity.Metrics[MetricType.HAPPINESS].Value;

            appDbContext.SaveChangesAsync().Wait();

            // Act
            await petService.DegradeMetrics();

            var pet = await petService.GetAsync(125);

            // Assert
            Assert.True(pet.Metrics[MetricType.HAPPINESS].Value < happinessAtTimeOfCreation);
        }
Ejemplo n.º 3
0
        public async void TestCreateUserAsync()
        {
            // Arrange
            AppDbContext   appDbContext   = AppDbContextMock.GetAppDbContext();
            UserRepository userRepository = new UserRepository(appDbContext);
            UserService    userService    = new UserService(userRepository, new UnitOfWork(appDbContext));

            // Act
            var user = await userService.CreateAsync(new User { Name = "Alasdair" });

            // Assert
            Assert.NotNull(user);
        }
Ejemplo n.º 4
0
        public async void TestListUsersAsync()
        {
            // Arrange
            AppDbContext   appDbContext   = AppDbContextMock.GetAppDbContext();
            UserRepository userRepository = new UserRepository(appDbContext);
            UserService    userService    = new UserService(userRepository, new UnitOfWork(appDbContext));

            appDbContext.Users.Add(new User {
                Id = 105, Name = "Johnny"
            });
            appDbContext.SaveChangesAsync().Wait();

            // Act
            var users = await userService.ListAsync();

            // Assert
            Assert.True(users.ToList().Count > 0);
        }
Ejemplo n.º 5
0
        public async void TestCreatePetAsync()
        {
            // Arrange
            AppDbContext   appDbContext   = AppDbContextMock.GetAppDbContext();
            PetRepository  petRepository  = new PetRepository(appDbContext);
            UserRepository userRepository = new UserRepository(appDbContext);
            PetService     petService     = new PetService(petRepository, userRepository, new UnitOfWork(appDbContext));

            appDbContext.Users.Add(new User {
                Id = 215, Name = "Michael"
            });
            appDbContext.SaveChangesAsync().Wait();

            // Act
            var pet = await petService.CreateAsync(new Cat { Name = "Clause", UserId = 215 });

            // Assert
            Assert.NotNull(pet);
        }
Ejemplo n.º 6
0
        public async void TestGetUserAsync()
        {
            // Arrange
            AppDbContext   appDbContext   = AppDbContextMock.GetAppDbContext();
            UserRepository userRepository = new UserRepository(appDbContext);
            UserService    userService    = new UserService(userRepository, new UnitOfWork(appDbContext));

            appDbContext.Users.Add(new User {
                Id = 100, Name = "Josh"
            });
            appDbContext.SaveChangesAsync().Wait();

            // Act
            var user = await userService.GetAsync(100);

            // Assert
            Assert.NotNull(user);
            Assert.Equal(100, user.Id);
            Assert.Equal("Josh", user.Name);
        }
Ejemplo n.º 7
0
        public async void TestDeleteUserAsync()
        {
            // Arrange
            AppDbContext   appDbContext   = AppDbContextMock.GetAppDbContext();
            UserRepository userRepository = new UserRepository(appDbContext);
            UserService    userService    = new UserService(userRepository, new UnitOfWork(appDbContext));

            appDbContext.Add(new User {
                Id = 110, Name = "Daniel"
            });
            await appDbContext.SaveChangesAsync();

            // Act
            var userDeleted = await userService.DeleteAsync(110);

            var findUser = await userService.GetAsync(110);

            // Assert
            Assert.NotNull(userDeleted);
            Assert.Equal("Daniel", userDeleted.Name);
            Assert.Null(findUser);
        }
Ejemplo n.º 8
0
        public async void TestListPetsAsync()
        {
            // Arrange
            AppDbContext   appDbContext   = AppDbContextMock.GetAppDbContext();
            PetRepository  petRepository  = new PetRepository(appDbContext);
            UserRepository userRepository = new UserRepository(appDbContext);
            PetService     petService     = new PetService(petRepository, userRepository, new UnitOfWork(appDbContext));

            appDbContext.Users.Add(new User {
                Id = 205, Name = "Eva"
            });
            appDbContext.Pets.Add(new Dog {
                Id = 105, Name = "Meowser", UserId = 205
            });
            appDbContext.SaveChangesAsync().Wait();

            // Act
            var pets = await petService.ListAsync();

            // Assert
            Assert.True(pets.ToList().Count > 0);
        }
Ejemplo n.º 9
0
        public async void TestGetPetAsync()
        {
            // Arrange
            AppDbContext   appDbContext   = AppDbContextMock.GetAppDbContext();
            PetRepository  petRepository  = new PetRepository(appDbContext);
            UserRepository userRepository = new UserRepository(appDbContext);
            PetService     petService     = new PetService(petRepository, userRepository, new UnitOfWork(appDbContext));

            appDbContext.Users.Add(new User {
                Id = 200, Name = "Owen"
            });
            appDbContext.Pets.Add(new Dog {
                Id = 100, Name = "Woofus", UserId = 200
            });
            appDbContext.SaveChangesAsync().Wait();

            // Act
            var pet = await petService.GetAsync(100);

            // Assert
            Assert.NotNull(pet);
            Assert.Equal(100, pet.Id);
            Assert.Equal("Woofus", pet.Name);
        }
Ejemplo n.º 10
0
        public async void TestInteractAsync()
        {
            // Arrange
            AppDbContext   appDbContext   = AppDbContextMock.GetAppDbContext();
            PetRepository  petRepository  = new PetRepository(appDbContext);
            UserRepository userRepository = new UserRepository(appDbContext);
            PetService     petService     = new PetService(petRepository, userRepository, new UnitOfWork(appDbContext));

            appDbContext.Users.Add(new User {
                Id = 220, Name = "Rachel"
            });
            var hungerAtTimeOfCreation = appDbContext.Add(new Dog {
                Id = 120, Name = "Harvey", UserId = 220
            })
                                         .Entity.Metrics[MetricType.HUNGER].Value;

            appDbContext.SaveChangesAsync().Wait();

            // Act
            var newPetState = await petService.InteractAsync(120, MetricType.HUNGER);

            // Assert
            Assert.True(newPetState.Metrics[MetricType.HUNGER].Value < hungerAtTimeOfCreation);
        }