예제 #1
0
        public async Task CreateUserAsync()
        {
            using var scope = ServiceProviderAccessor.GetServiceProviderScope();

            var userService = scope.ServiceProvider.GetService <IUserService>();
            var newUserId   = await userService.CreateUserAsync("Test user");

            var users = await userService.GetUsersAsync();

            Assert.NotNull(users.FirstOrDefault(x => x.Id == newUserId));
        }
예제 #2
0
        public async Task AdoptAnimalAsync()
        {
            using var scope = ServiceProviderAccessor.GetServiceProviderScope();

            var userService     = scope.ServiceProvider.GetService <IUserService>();
            var adoptionService = scope.ServiceProvider.GetService <IAdoptionService>();

            var newUserId = await userService.CreateUserAsync("Test user");

            var newAnimalId = await adoptionService.AdoptAnimalAsync(newUserId, "Test dog", AnimalType.Dog);

            var animals = await adoptionService.GetAnimalsAsync();

            Assert.NotNull(animals.FirstOrDefault(x => x.Id == newAnimalId));
        }
예제 #3
0
        public async Task LowerHappinessAsync()
        {
            using var scope = ServiceProviderAccessor.GetServiceProviderScope();

            var userService         = scope.ServiceProvider.GetService <IUserService>();
            var adoptionService     = scope.ServiceProvider.GetService <IAdoptionService>();
            var animalStatusService = scope.ServiceProvider.GetService <IAnimalStatusService>();

            var newUserId = await userService.CreateUserAsync("Test user");

            var newAnimalId = await adoptionService.AdoptAnimalAsync(newUserId, "Test dog", AnimalType.Dog);

            var initHappiness = await animalStatusService.GetHappinessAsync(newUserId, newAnimalId);

            await animalStatusService.LowerHappiness(newAnimalId);

            var afterHappiness = await animalStatusService.GetHappinessAsync(newUserId, newAnimalId);

            Assert.True(afterHappiness < initHappiness);
        }
예제 #4
0
        public async Task FeedAnimalAsync()
        {
            using var scope = ServiceProviderAccessor.GetServiceProviderScope();

            var userService         = scope.ServiceProvider.GetService <IUserService>();
            var adoptionService     = scope.ServiceProvider.GetService <IAdoptionService>();
            var feedingService      = scope.ServiceProvider.GetService <IFeedingService>();
            var animalStatusService = scope.ServiceProvider.GetService <IAnimalStatusService>();

            var newUserId = await userService.CreateUserAsync("Test user");

            var newAnimalId = await adoptionService.AdoptAnimalAsync(newUserId, "Test dog", AnimalType.Dog);

            var initHunger = await animalStatusService.GetHungerAsync(newUserId, newAnimalId);

            await feedingService.FeedAnimalAsync(newUserId, newAnimalId);

            var afterHunger = await animalStatusService.GetHungerAsync(newUserId, newAnimalId);

            Assert.True(afterHunger < initHunger);
        }