コード例 #1
0
        public async Task GetIdByName_WithInvalidData_ShouldWorkCorrectly(string name)
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            var repository = new EfDeletableEntityRepository <Location>(context);
            var service    = new LocationsService(repository);


            var actualId = service.GetIdByName(name);

            Assert.True(actualId == 0);
        }
コード例 #2
0
        public async Task GetIdByName_ShouldWorkCorrectly()
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            var repository = new EfDeletableEntityRepository <Location>(context);
            var service    = new LocationsService(repository);

            var firstLocation = context.Locations.First();
            var name          = firstLocation.Name;
            var expectedId    = firstLocation.Id;

            var actualId = service.GetIdByName(name);

            Assert.True(expectedId == actualId);
        }
コード例 #3
0
        public void GetIdByNameShould_ReturnZeroIfInvalidLocationName()
        {
            var options = new DbContextOptionsBuilder <CarRentalDbContext>()
                          .UseInMemoryDatabase(databaseName: "CarRental_Database_0ForInvalidLocation")
                          .Options;
            var dbContext = new CarRentalDbContext(options);

            var locationsService = new LocationsService(dbContext);

            var location = new Location
            {
                Id   = 1,
                Name = locationNameOne
            };

            locationsService.CreateLocation(location);

            var result = locationsService.GetIdByName(locationNameThree).GetAwaiter().GetResult();

            Assert.Equal(0, result);
        }