Beispiel #1
0
        public async Task UpdateAsync_WithNullId_ReturnsFalse()
        {
            // Arrange
            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            context.CarManufacturers.AddRange(
                new CarManufacturer
            {
                Name = "OtherManufacturer1"
            },
                new CarManufacturer
            {
                Name = "OtherManufacturer2"
            });

            context.SaveChanges();

            var manufacturersService = new ManufacturersService(new EfRepository <CarManufacturer>(context));

            var serviceModel = new CarManufacturerServiceModel
            {
                Id   = null,
                Name = "TestName"
            };

            // Act
            var result = await manufacturersService.UpdateAsync(serviceModel);

            // Assert
            Assert.False(result);
        }
Beispiel #2
0
        public async Task CreateAsync_WithValidModel_WorksCorrectly()
        {
            // Arrange
            const string testName = "TestName";

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var manufacturersService = new ManufacturersService(new EfRepository <CarManufacturer>(context));

            var serviceModel = new CarManufacturerServiceModel
            {
                Name = testName
            };

            // Act
            var result = await manufacturersService.CreateAsync(serviceModel);

            // Assert
            Assert.True(result);

            var addedToDb = await context.CarManufacturers.AnyAsync(m => m.Name == testName);

            Assert.True(addedToDb);
        }
Beispiel #3
0
        public async Task GetAsync_WithCorrectId_WorksCorrectly()
        {
            // Arrange
            const string testName = "TestName";

            var manufacturer = new CarManufacturer
            {
                Name = testName
            };

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            context.CarManufacturers.AddRange(
                manufacturer,
                new CarManufacturer
            {
                Name = "OtherManufacturer1"
            },
                new CarManufacturer
            {
                Name = "OtherManufacturer2"
            });

            context.SaveChanges();

            var manufacturersService = new ManufacturersService(new EfRepository <CarManufacturer>(context));

            // Act
            var actualResult = (await manufacturersService.GetAsync(manufacturer.Id)).Name;

            // Assert
            Assert.Equal(testName, actualResult);
        }
Beispiel #4
0
        public async Task GetAll_WithData_WorksCorrectly()
        {
            // Arrange
            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            context.CarManufacturers.AddRange(
                new CarManufacturer
            {
                Name = "Manufacturer1"
            },
                new CarManufacturer
            {
                Name = "Manufacturer2"
            });

            context.SaveChanges();

            var manufacturersService = new ManufacturersService(new EfRepository <CarManufacturer>(context));

            // Act
            var actualResult = (await manufacturersService.GetAllAsync()).Count();

            // Assert
            const int expectedResult = 2;

            Assert.Equal(expectedResult, actualResult);
        }
Beispiel #5
0
        public async Task ExistsAsync_WithUppercaseName_ReturnsTrue()
        {
            // Arrange
            const string testName = "TestName";

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            context.CarManufacturers.AddRange(
                new CarManufacturer
            {
                Name = testName
            },
                new CarManufacturer
            {
                Name = "OtherManufacturer"
            });

            context.SaveChanges();

            var manufacturersService = new ManufacturersService(new EfRepository <CarManufacturer>(context));

            // Act
            var result = await manufacturersService.ExistsByNameAsync(testName.ToUpperInvariant());

            // Assert
            Assert.True(result);
        }
Beispiel #6
0
        public async Task GetAsync_WithNonExistentId_ReturnsNull()
        {
            // Arrange
            var testId = Guid.NewGuid().ToString();

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            context.CarManufacturers.AddRange(
                new CarManufacturer
            {
                Name = "OtherManufacturer1"
            },
                new CarManufacturer
            {
                Name = "OtherManufacturer2"
            });

            context.SaveChanges();

            var manufacturersService = new ManufacturersService(new EfRepository <CarManufacturer>(context));

            // Act
            var result = await manufacturersService.GetAsync(testId);

            // Assert
            Assert.Null(result);
        }
        public static void TestFixtureSetup(TestContext context)
        {
            con = new NpgsqlConnection(cs);
            con.Open();

            regionsRepository       = new RegionsRepository(con);
            countriesRepository     = new CountriesRepository(con);
            manufacturersRepository = new ManufacturersRepository(con);
            manufacturersService    = new ManufacturersService(con);

            regionsRepository.Save(Region1);
            regionsRepository.Save(Region2);
            regionsRepository.Save(Region3);
            regionsRepository.Flush();

            countriesRepository.Save(Country1);
            countriesRepository.Save(Country2);
            countriesRepository.Save(Country3);
            countriesRepository.Save(Country4);
            countriesRepository.Save(Country5);
            countriesRepository.Flush();

            manufacturersRepository.Save(Manufacturer1);
            manufacturersRepository.Save(Manufacturer2);
            manufacturersRepository.Save(Manufacturer3);
            manufacturersRepository.Save(Manufacturer4);
            manufacturersRepository.Save(Manufacturer5);
            manufacturersRepository.Save(Manufacturer6);
            manufacturersRepository.Save(Manufacturer7);
            manufacturersRepository.Save(Manufacturer8);
            manufacturersRepository.Save(Manufacturer9);
            manufacturersRepository.Flush();
        }
Beispiel #8
0
        public async Task DeleteAsync_WithNullId_ReturnsFalse()
        {
            // Arrange
            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            context.CarManufacturers.AddRange(
                new CarManufacturer
            {
                Name = "OtherManufacturer1"
            },
                new CarManufacturer
            {
                Name = "OtherManufacturer2"
            });

            context.SaveChanges();

            var manufacturersService = new ManufacturersService(new EfRepository <CarManufacturer>(context));

            // Act
            var result = await manufacturersService.DeleteAsync(null);

            // Assert
            Assert.False(result);

            var dbCount = await context.CarManufacturers.CountAsync();

            Assert.Equal(2, dbCount);
        }
        private static ManufacturersService InitializeCategoriesService()
        {
            MapperInitializer.InitializeMapper();
            var context    = InitializeContext.CreateContextForInMemory();
            var repository = new EfDeletableEntityRepository <Manufacturer>(context);
            var service    = new ManufacturersService(repository);

            return(service);
        }
Beispiel #10
0
        /// <summary>Initializes a new instance of the <see cref="FilterCarsForm"/> class.</summary>
        /// <param name="returnCriteria">The return criteria the parent form is currently set to.</param>
        /// <param name="con">The database connection.</param>
        /// <exception cref="ArgumentNullException">returnCriteria or con</exception>
        public FilterCarsForm(CarSearchCriteria returnCriteria, NpgsqlConnection con)
        {
            this.returnCriteria = returnCriteria ?? throw new ArgumentNullException(nameof(returnCriteria));
            this.con            = con ?? throw new ArgumentNullException(nameof(con));

            manufacturersService = new ManufacturersService(con);
            countiresService     = new CountriesService(con);
            regionsService       = new RegionsService(con);

            InitializeComponent();
        }
        /// <summary>Initializes a new instance of the <see cref="OwnerCarsForm"/> class.</summary>
        /// <param name="con">The connection.</param>
        /// <exception cref="ArgumentNullException">con</exception>
        public OwnerCarsForm(NpgsqlConnection con)
        {
            this.con = con ?? throw new ArgumentNullException(nameof(con));

            manufacturersService = new ManufacturersService(con);
            carsService          = new CarsService(con);
            ownerCarsService     = new OwnerCarsService(con);
            statisticService     = new GTSportStatisticService(con);

            //AddCarTestData();

            InitializeComponent();
        }
Beispiel #12
0
        public async Task DeleteAsync_WithCarModels_DoesNotDelete()
        {
            // Arrange
            const string testName = "TestName";

            var manufacturer = new CarManufacturer
            {
                Name   = testName,
                Models = new List <CarModel>
                {
                    new CarModel
                    {
                        Model = "TestModel"
                    }
                }
            };

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            context.CarManufacturers.AddRange(
                manufacturer,
                new CarManufacturer
            {
                Name = "OtherManufacturer1"
            },
                new CarManufacturer
            {
                Name = "OtherManufacturer2"
            });

            context.SaveChanges();

            var manufacturersService = new ManufacturersService(new EfRepository <CarManufacturer>(context));

            // Act
            var result = await manufacturersService.DeleteAsync(manufacturer.Id);

            // Assert
            Assert.False(result);

            var existsInDb = await context.CarManufacturers.AnyAsync(m => m.Name == testName);

            Assert.True(existsInDb);

            var dbCount = await context.CarManufacturers.CountAsync();

            Assert.Equal(3, dbCount);
        }
Beispiel #13
0
        public async Task CreateManufacturerShouldCreateNewManufacturer()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            var service = new ManufacturersService(context);

            var manufacturerId = await service.CreateManufacturerAsync("TestManufacturer");

            var manufacturersCount = service.GetAllManufacturersCount();
            var expectedCount      = 1;

            Assert.Equal(expectedCount, manufacturersCount);
            Assert.Equal(1, manufacturerId);
        }
Beispiel #14
0
        public async Task GetAll_WithNoData_ReturnsEmptyEnumerable()
        {
            // Arrange
            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var manufacturersService = new ManufacturersService(new EfRepository <CarManufacturer>(context));

            // Act
            var actualResult = (await manufacturersService.GetAllAsync()).Count();

            // Assert
            const int expectedResult = 0;

            Assert.Equal(expectedResult, actualResult);
        }
Beispiel #15
0
        public async Task UpdateAsync_WithInvalidModel_DoesNotChange()
        {
            // Arrange
            const string expectedResult = "InitialName";

            var manufacturer = new CarManufacturer
            {
                Name = expectedResult
            };

            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            context.CarManufacturers.AddRange(
                manufacturer,
                new CarManufacturer
            {
                Name = "OtherManufacturer1"
            },
                new CarManufacturer
            {
                Name = "OtherManufacturer2"
            });

            context.SaveChanges();

            var manufacturersService = new ManufacturersService(new EfRepository <CarManufacturer>(context));

            var serviceModel = new CarManufacturerServiceModel
            {
                Id   = manufacturer.Id,
                Name = "a"
            };

            // Act
            var result = await manufacturersService.UpdateAsync(serviceModel);

            // Assert
            Assert.False(result);

            var actualResult = (await context.CarManufacturers.SingleAsync(m => m.Id == manufacturer.Id)).Name;

            Assert.Equal(expectedResult, actualResult);
        }
Beispiel #16
0
        public async Task GetAllManufacturersShouldReturnMaxPageSize()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            for (int i = 0; i < 100; i++)
            {
                await context.Manufacturers.AddAsync(new Manufacturer { Name = i.ToString() });
            }

            await context.SaveChangesAsync();

            var service = new ManufacturersService(context);

            var manufacturers      = service.GetAllManufacturers <ManufacturerViewModel>(1);
            var manufacturersCount = manufacturers.ToList().Count();
            var exepcetedCount     = GlobalConstants.PageSize;

            Assert.Equal(exepcetedCount, manufacturersCount);
        }
Beispiel #17
0
        public async Task CreateAsync_WithInvalidModel_WorksCorrectly()
        {
            // Arrange
            var context = new PoolItDbContext(new DbContextOptionsBuilder <PoolItDbContext>()
                                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                              .Options);

            var manufacturersService = new ManufacturersService(new EfRepository <CarManufacturer>(context));

            var serviceModel = new CarManufacturerServiceModel();

            // Act
            var result = await manufacturersService.CreateAsync(serviceModel);

            // Assert
            Assert.False(result);

            var dbCount = await context.CarManufacturers.CountAsync();

            Assert.Equal(0, dbCount);
        }
Beispiel #18
0
 public ManufacturersController(LeashRingsService lrs, ManufacturersService ms)
 {
     _lrs = lrs;
     _ms  = ms;
 }
Beispiel #19
0
 public ManufacturersController(ManufacturersService ms, ShoesService ss)
 {
     _ms = ms;
     _ss = ss;
 }