public void NullCollection_ShouldNotThrow() { IUserConfirmation uc = new ThrowOnTriggerUserConfirmation(); var prop = new PropertyPair { Key = "A", Value = "a" }; ICommand cmd = new AddPropertyCommand(null, prop, uc); cmd.Execute(); }
public void NullProperty_ShouldNotEditEmptyCollection() { IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair>()); IUserConfirmation uc = new ThrowOnTriggerUserConfirmation(); ICommand cmd = new AddPropertyCommand(file, null, uc); cmd.Execute(); Assert.Empty(file.GetProperties()); }
public async Task <int> AddAsync(int agencyId, AddPropertyCommand command) { var propertyModel = Mapper.Map <AddPropertyCommand, Property>(command, opt => opt.AfterMap((src, dest) => dest.AgencyId = agencyId)); _dbContext.Properties.Add(propertyModel); await _dbContext.SaveChangesAsync(); return(propertyModel.Id); }
public async Task <IActionResult> Register(AddPropertyCommand command) { var response = await mediator.Send(command); if (response) { return(Ok()); } return(BadRequest()); }
public void ShouldAddIntoEmptyCollection() { IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair>()); IUserConfirmation uc = new ThrowOnTriggerUserConfirmation(); var prop = new PropertyPair { Key = "greeting", Value = "Hello, World!" }; ICommand cmd = new AddPropertyCommand(file, prop, uc); cmd.Execute(); var collection = file.GetProperties(); Assert.Single(collection); Assert.Same(prop, collection.First()); }
public void NullProperty_ShouldNotEditFilledCollection() { IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair> { new PropertyPair { Key = "A", Value = "a" }, new PropertyPair { Key = "B", Value = "b" } }); IUserConfirmation uc = new ThrowOnTriggerUserConfirmation(); ICommand cmd = new AddPropertyCommand(file, null, uc); cmd.Execute(); Assert.Equal(2, file.GetProperties().Count()); }
public void WhenUserDeniesShouldNotAddDuplicateValue() { IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair> { new PropertyPair { Key = "A", Value = "a" }, new PropertyPair { Key = "B", Value = "b" } }); IUserConfirmation uc = new AlwaysDenyingUserConfirmation(); var prop = new PropertyPair { Key = "greeting", Value = "b" }; ICommand cmd = new AddPropertyCommand(file, prop, uc); cmd.Execute(); Assert.Equal(2, file.GetProperties().Count()); }
public void ShouldUpdateExistingIfKeyAlreadyExists() { IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair> { new PropertyPair { Key = "A", Value = "a" }, new PropertyPair { Key = "B", Value = "b" } }); IUserConfirmation uc = new ThrowOnTriggerUserConfirmation(); var prop = new PropertyPair { Key = "B", Value = "Hello, World!" }; ICommand cmd = new AddPropertyCommand(file, prop, uc); cmd.Execute(); Assert.Equal(2, file.GetProperties().Count()); Assert.Equal("Hello, World!", file.GetProperties().Last().Value); }
public void ShouldBeAddedAtTheEndOfCollection() { IPropertiesFile file = new InMemoryPropertiesFile(new List <PropertyPair> { new PropertyPair { Key = "A", Value = "a" }, new PropertyPair { Key = "B", Value = "b" } }); IUserConfirmation uc = new ThrowOnTriggerUserConfirmation(); var prop = new PropertyPair { Key = "greeting", Value = "Hello, World!" }; ICommand cmd = new AddPropertyCommand(file, prop, uc); cmd.Execute(); var collection = file.GetProperties(); Assert.Equal(3, collection.Count()); Assert.Same(prop, collection.Last()); }
public async Task <BaseDto> AddPropertyHandler([FromBody] AddPropertyCommand cmd) { var cmdResponse = await _mediator.Send(cmd); return(cmdResponse); }