Beispiel #1
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);
            });
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }