public async Task CreateAsync_WithEmptyNameShouldThrowArgumentNullException() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var roadObjectService = new RoadObjectService(context); var createRoadObjectServiceModel = new CreateRoadObjectServiceModel(); var roadObjectName = " "; createRoadObjectServiceModel.Name = roadObjectName; await Assert.ThrowsAsync <ArgumentNullException>(async() => { await roadObjectService.CreateAsync(createRoadObjectServiceModel); }); }
public async Task CreateAsync_WithOverMaxNameLengthShouldThrowInvalidOperationException() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var roadObjectService = new RoadObjectService(context); var createRoadObjectServiceModel = new CreateRoadObjectServiceModel(); var roadObjectName = "qwertyuiop qwertyuiop qwertyuiop qwertyuiop qwertyuiop"; createRoadObjectServiceModel.Name = roadObjectName; var message = "Road object's name cannot be more than 50 characters."; var exception = await Assert.ThrowsAsync <InvalidOperationException>(async() => { await roadObjectService.CreateAsync(createRoadObjectServiceModel); }); Assert.Equal(message, exception.Message); }
public async Task CreateAsync_ShouldSuccessfullyCreate() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var roadObjectService = new RoadObjectService(context); var createRoadObjectServiceModel = new CreateRoadObjectServiceModel(); var roadObjectName = "RON 1"; createRoadObjectServiceModel.Name = roadObjectName; await roadObjectService.CreateAsync(createRoadObjectServiceModel); var expectedResult = roadObjectName; var actualResult = roadObjectService .All() .First() .Name; Assert.True(expectedResult == actualResult); }
public async Task CreateAsync_WithExistingNameShouldThrowInvalidOperationException() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); await this.SeedDataAsync(context); var roadObjectService = new RoadObjectService(context); var createRoadObjectServiceModel = new CreateRoadObjectServiceModel(); var roadObjectName = "RON 1"; createRoadObjectServiceModel.Name = roadObjectName; var message = "Road object's name already exists."; var exception = await Assert.ThrowsAsync <InvalidOperationException>(async() => { await roadObjectService.CreateAsync(createRoadObjectServiceModel); }); Assert.Equal(message, exception.Message); }