Example #1
0
        public async Task EditAsync_ShouldSuccessfullyEdit()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var asphaltMixtureService          = new AsphaltMixtureService(context);
            var editAsphaltMixtureServiceModel = new EditAsphaltMixtureServiceModel();
            var asphaltMixtureId   = 1;
            var asphaltMixtureType = "AMT 3";

            editAsphaltMixtureServiceModel.Id   = asphaltMixtureId;
            editAsphaltMixtureServiceModel.Type = asphaltMixtureType;

            await asphaltMixtureService.EditAsync(editAsphaltMixtureServiceModel);

            var expectedResult = asphaltMixtureType;
            var actualResult   = asphaltMixtureService
                                 .All()
                                 .First()
                                 .Type;

            Assert.True(expectedResult == actualResult);
        }
Example #2
0
        public async Task DeleteByIdAsync_ShouldSuccessfullyDelete()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var asphaltMixtureService            = new AsphaltMixtureService(context);
            var deleteAsphaltMixtureServiceModel = new DeleteAsphaltMixtureServiceModel();

            deleteAsphaltMixtureServiceModel.Id = 1;

            await asphaltMixtureService.DeleteByIdAsync(deleteAsphaltMixtureServiceModel.Id);

            var expectedResult = 1;
            var actualResult   = asphaltMixtureService
                                 .All()
                                 .Count();
            var expectedResult2 = "AMT 2";
            var actualResult2   = asphaltMixtureService
                                  .All()
                                  .First()
                                  .Type;

            Assert.True(expectedResult == actualResult);
            Assert.True(expectedResult2 == actualResult2);
        }
Example #3
0
        public void All_ShouldReturnEmptyResult()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var asphaltMixtureService = new AsphaltMixtureService(context);

            var actualResult = asphaltMixtureService.All();

            Assert.True(actualResult.Count() == 0);
        }
Example #4
0
        public async Task ExistAsync_ShouldNotExist()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var asphaltMixtureService = new AsphaltMixtureService(context);

            Assert.False(await asphaltMixtureService.ExistsAsync(3));
        }
Example #5
0
        public async Task GetByIdAsync_WithNonExistingId_ShouldThrowArgumentNullException()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var asphaltMixtureService = new AsphaltMixtureService(context);

            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await asphaltMixtureService.GetByIdAsync(3);
            });
        }
Example #6
0
        public async Task CreateAsync_WithEmptyNameShouldThrowArgumentNullException()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var asphaltMixtureService            = new AsphaltMixtureService(context);
            var createAsphaltMixtureServiceModel = new CreateAsphaltMixtureServiceModel();
            var asphaltMixtureType = "  ";

            createAsphaltMixtureServiceModel.Type = asphaltMixtureType;

            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await asphaltMixtureService.CreateAsync(createAsphaltMixtureServiceModel);
            });
        }
Example #7
0
        public async Task GetByIdAsync_ShouldSuccessfullyGet()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var asphaltMixtureService = new AsphaltMixtureService(context);

            await asphaltMixtureService.GetByIdAsync(1);

            var expectedResult = "AMT 1";
            var actualResult   = await asphaltMixtureService.GetByIdAsync(1);

            Assert.True(expectedResult == actualResult.Type);
        }
Example #8
0
        public async Task All_ShouldReturnCorrectResult()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var asphaltMixtureService = new AsphaltMixtureService(context);

            var actualResult   = asphaltMixtureService.All().Select(x => x.Type).ToList();
            var expectedResult = this.GetDummyData().Select(x => x.Type).ToList();

            for (int i = 0; i < actualResult.Count; i++)
            {
                Assert.True(expectedResult[i] == actualResult[i]);
            }
        }
Example #9
0
        public async Task CreateAsync_WithOverMaxNameLengthShouldThrowInvalidOperationException()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var asphaltMixtureService            = new AsphaltMixtureService(context);
            var createAsphaltMixtureServiceModel = new CreateAsphaltMixtureServiceModel();
            var asphaltMixtureType = "qwertyuiop qwertyuiop qwertyuiop qwertyuiop qwertyuiop";

            createAsphaltMixtureServiceModel.Type = asphaltMixtureType;
            var message = "Asphalt mixture's type cannot be more than 30 characters.";

            var exception = await Assert.ThrowsAsync <InvalidOperationException>(async() =>
            {
                await asphaltMixtureService.CreateAsync(createAsphaltMixtureServiceModel);
            });

            Assert.Equal(message, exception.Message);
        }
Example #10
0
        public async Task CreateAsync_ShouldSuccessfullyCreate()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var asphaltMixtureService            = new AsphaltMixtureService(context);
            var createAsphaltMixtureServiceModel = new CreateAsphaltMixtureServiceModel();
            var asphaltMixtureType = "AMT 1";

            createAsphaltMixtureServiceModel.Type = asphaltMixtureType;

            await asphaltMixtureService.CreateAsync(createAsphaltMixtureServiceModel);

            var expectedResult = asphaltMixtureType;
            var actualResult   = asphaltMixtureService
                                 .All()
                                 .First()
                                 .Type;

            Assert.True(expectedResult == actualResult);
        }
Example #11
0
        public async Task CreateAsync_WithExistingNameShouldThrowInvalidOperationException()
        {
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var asphaltMixtureService            = new AsphaltMixtureService(context);
            var createAsphaltMixtureServiceModel = new CreateAsphaltMixtureServiceModel();
            var asphaltMixtureType = "AMT 1";

            createAsphaltMixtureServiceModel.Type = asphaltMixtureType;
            var message = "Asphalt mixture's type already exists.";

            var exception = await Assert.ThrowsAsync <InvalidOperationException>(async() =>
            {
                await asphaltMixtureService.CreateAsync(createAsphaltMixtureServiceModel);
            });

            Assert.Equal(message, exception.Message);
        }