Exemple #1
0
        public void CourtTownCreateTest()
        {
            //Arrange
            var courtTown = new CourtTown
            {
                Id       = 3,
                TownName = "Rousse3",
                Address  = "myAddress3"
            };

            var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                .UseInMemoryDatabase("testDb");
            var dbContext = new ApplicationDbContext(optionBuilder.Options);
            //await dbContext.CourtTowns.AddAsync(courtTown);
            //await dbContext.SaveChangesAsync();

            var service = new CourtTownService(dbContext);

            //Act
            var result = service.CreateAsync(courtTown.TownName, courtTown.Address);
            var name   = dbContext.CourtTowns.Where(x => x.TownName == courtTown.TownName)
                         .Select(x => x.TownName).FirstOrDefault();

            //Assert
            //Assert.NotNull(result);
            //Assert.IsType<List<CourtTownEditViewModel>>(result.Result);
            Assert.True(result.IsCompletedSuccessfully);
            Assert.Equal("Rousse3", name);
            //Assert.Equal("Rousse", result.Result.TownName);
            //Assert.Equal("myAddress", result.Result.Address);
            //Assert.Equal(1, result.Result.Id);
        }
Exemple #2
0
        public async Task CourtTownAllTest()
        {
            //Arrange
            var courtTown = new CourtTown
            {
                Id       = 20,
                TownName = "Rousse20",
                Address  = "myAddress20"
            };

            var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                .UseInMemoryDatabase("testDb");
            var dbContext = new ApplicationDbContext(optionBuilder.Options);
            await dbContext.CourtTowns.AddAsync(courtTown);

            await dbContext.SaveChangesAsync();

            var service = new CourtTownService(dbContext);

            //Act
            var result = service.AllAsync();

            //Assert
            Assert.NotNull(result);
            Assert.IsType <List <CourtTownEditViewModel> >(result.Result);
            //Assert.Equal("Rousse", result.Result.TownName);
            //Assert.Equal("myAddress", result.Result.Address);
            //Assert.Equal(1, result.Result.Id);
        }
Exemple #3
0
        public async Task CourtTownReturnDetails()
        {
            //Arrange
            var courtTown = new CourtTown
            {
                Id       = 2,
                TownName = "Rousse2",
                Address  = "myAddress2"
            };

            var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                .UseInMemoryDatabase("testDb");
            var dbContext = new ApplicationDbContext(optionBuilder.Options);
            await dbContext.CourtTowns.AddAsync(courtTown);

            await dbContext.SaveChangesAsync();

            var service = new CourtTownService(dbContext);

            //Act
            var result = service.DetailsAsync(2);

            //Assert
            Assert.NotNull(result);
            Assert.Equal("Rousse2", result.Result.TownName);
            Assert.Equal("myAddress2", result.Result.Address);
            Assert.Equal(2, result.Result.Id);
        }
Exemple #4
0
        public async Task CourtTownDeleteTest()
        {
            //Arrange
            var courtTown = new CourtTown
            {
                Id       = 6,
                TownName = "Rousse",
                Address  = "myAddress"
            };

            var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                .UseInMemoryDatabase("testDb");
            var dbContext = new ApplicationDbContext(optionBuilder.Options);
            await dbContext.CourtTowns.AddAsync(courtTown);

            await dbContext.SaveChangesAsync();

            var service = new CourtTownService(dbContext);

            //Act
            var result      = service.DeleteAsync(6);
            var myCourtTown = dbContext.CourtTowns.Where(x => x.Id == 6).Select(x => x.TownName)
                              .FirstOrDefault();

            //Assert
            Assert.Null(myCourtTown);
            Assert.True(result.IsCompletedSuccessfully);
        }
        public async Task CourtDeleteTest()
        {
            var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                .UseInMemoryDatabase("testDb");
            var dbContext = new ApplicationDbContext(optionBuilder.Options);

            var townService = new CourtTownService(dbContext);

            await townService.CreateAsync("Rousse", "Боримечка 43");

            await townService.CreateAsync("София", "Боримечка 44");

            var townId = dbContext.CourtTowns.Where(x => x.Id == 1)
                         .Select(x => x.Id)
                         .FirstOrDefault();

            var courtService = new CourtService(dbContext);
            await courtService.CreateAsync("Районен", townId);

            await courtService.CreateAsync("Окръжен", townId);

            var courtId = dbContext.Courts.Where(x => x.CourtType.ToString() == "Окръжен")
                          .Select(x => x.Id).FirstOrDefault();

            //Act
            var result  = courtService.DeleteAsync(courtId);
            var myCourt = dbContext.Courts.Where(x => x.Id == courtId)
                          .Select(x => x.CourtTown.TownName).FirstOrDefault();

            //Assert
            Assert.Null(myCourt);
            //Assert.True(result.IsCompletedSuccessfully);
        }
        public async Task CourtEditTest()
        {
            var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                .UseInMemoryDatabase("testDb");
            var dbContext = new ApplicationDbContext(optionBuilder.Options);

            var townService = new CourtTownService(dbContext);

            await townService.CreateAsync("Rousse", "Боримечка 43");

            await townService.CreateAsync("Rousse", "Боримечка 44");

            var town = dbContext.CourtTowns.Where(x => x.Id == 1)
                       .Select(x => x.Id)
                       .FirstOrDefault();

            var courtService = new CourtService(dbContext);
            await courtService.CreateAsync("Окръжен", town);

            await courtService.CreateAsync("Районен", town);

            var courtId = dbContext.Courts.Where(x => x.Id == 0)
                          .Select(x => x.Id)
                          .FirstOrDefault();
            var result    = courtService.EditAsync(courtId, "окръжен", 1);
            var courtType = await courtService.DetailsAsync(1);

            Assert.True(result.IsCompletedSuccessfully);
            // Assert.Equal("окръжен", courtType.CourtType.ToString());
            Assert.NotNull(result);
        }