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); }); }
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); }
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); }
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); }