public async Task Hanlde_CreatePropertyCommand_AddsPropertyDefinitionToProjectAsync() { // arrange var project = CreateProject(); var entity = project.Schema.Entities.First(); var command = new CreatePropertyCommand { Id = project.Id, ParentEntityId = entity.Id, Name = "NewPropertyName", Description = "NewPropertyDescription", PropertyType = "Zuehlke.Eacm.String" }; var session = new Mock <ISession>(); session.Setup(s => s.Get <Project>(project.Id, command.ExpectedVersion, It.IsAny <CancellationToken>())).Returns(Task.FromResult(project)); var target = new ProjectCommandHandler(session.Object); // act await target.Handle(command); // assert var propertyDefinition = entity.Properties.FirstOrDefault(p => p.Name == command.Name); Assert.NotNull(propertyDefinition); Assert.Equal(command.Name, propertyDefinition.Name); Assert.Equal(command.Description, propertyDefinition.Description); Assert.Equal(command.PropertyType, propertyDefinition.PropertyType); session.Verify(s => s.Commit(It.IsAny <CancellationToken>())); }
internal override void Invoke(CommandProcessorContext cpc) { var viewModel = _property.GetRootViewModel(); Debug.Assert(viewModel != null, "Unable to find root view model from property: " + _property.Name); if (viewModel != null) { var entityType = viewModel.ModelXRef.GetExisting(_property.EntityType) as Model.Entity.EntityType; Debug.Assert(entityType != null); Model.Entity.Property property = null; if (_property is ScalarProperty) { property = CreatePropertyCommand.CreateDefaultProperty(cpc, _property.Name, entityType); var scalarProperty = _property as ScalarProperty; if (scalarProperty != null && scalarProperty.EntityKey) { CommandProcessor.InvokeSingleCommand(cpc, new SetKeyPropertyCommand(property, true)); } } else { property = CreateComplexPropertyCommand.CreateDefaultProperty(cpc, _property.Name, entityType); } viewModel.ModelXRef.Add(property, _property, viewModel.EditingContext); } }
public ActionResult Create(CreatePropertyCommand command) { var handler = new CreatePropertyCommandHandler(_context); command.SellerUserId = User.Identity.GetUserId(); handler.Handle(command); return(RedirectToAction("MyProperties")); }
public async Task <IActionResult> AddAsset([FromBody] CreatePropertyCommand command) { if (!ModelState.IsValid) { return(BadRequest(400)); } var result = await _mediator.Send(command); return(Ok(result)); }
public void HandleShouldAddProperty() { // Arrange var command = new CreatePropertyCommand(); // Act _handler.Handle(command); // Assert _context.Properties.Received(1).Add(Arg.Any <Models.Property>()); }
public void CreateProperty_does_not_create_Nullable_attribute_if_no_value() { var parentEntity = CreateEntityType <ConceptualEntityType>(); var createPropertyCommand = new CreatePropertyCommand("test", parentEntity, "Int32", null, null); using (var property = createPropertyCommand.CreateProperty()) { Assert.Equal( "<Property Name=\"test\" Type=\"Int32\" xmlns=\"http://schemas.microsoft.com/ado/2009/11/edm\" />", property.XElement.ToString()); } }
public ActionResult Create(CreatePropertyCommand command) { var handler = new CreatePropertyCommandHandler(_context); command.SellerUserId = User.Identity.GetUserId(); handler.Handle(command); ModelState.AddModelError("", "A post with this title already exists."); return(RedirectToAction("MyProperties")); }
public void HandleShouldAddPropertyWithCorrectNumberOfBedrooms() { // Arrange var command = new CreatePropertyCommand { NumberOfBedrooms = 3 }; // Act _handler.Handle(command); // Assert _context.Properties.Received(1).Add(Arg.Is <Models.Property>(x => x.NumberOfBedrooms == 3)); }
public void HandleShouldAddPropertyWithCorrectDescription() { // Arrange var command = new CreatePropertyCommand { Description = "A fantastic property." }; // Act _handler.Handle(command); // Assert _context.Properties.Received(1).Add(Arg.Is <Models.Property>(x => x.Description == "A fantastic property.")); }
public void HandleShouldAddPropertyWithCorrectStreetName() { // Arrange var command = new CreatePropertyCommand { StreetName = "Barnard Road" }; // Act _handler.Handle(command); // Assert _context.Properties.Received(1).Add(Arg.Is <Models.Property>(x => x.StreetName == "Barnard Road")); }
public void HandleShouldAddPropertyWithCorrectPropertyType() { // Arrange var command = new CreatePropertyCommand { PropertyType = "House" }; // Act _handler.Handle(command); // Assert _context.Properties.Received(1).Add(Arg.Is <Models.Property>(x => x.PropertyType == "House")); }
public void CreateProperty_sets_Name_attribute_before_type_for_store_property() { var parentEntity = CreateEntityType <StorageEntityType>(); var createPropertyCommand = new CreatePropertyCommand("test", parentEntity, "Int32", false, null); using (var property = createPropertyCommand.CreateProperty()) { Assert.IsType(typeof(StorageProperty), property); Assert.Contains(property, parentEntity.Properties()); Assert.Equal( "<Property Name=\"test\" Type=\"Int32\" Nullable=\"false\" xmlns=\"http://schemas.microsoft.com/ado/2009/11/edm/ssdl\" />", property.XElement.ToString()); } }
public void HandleShouldAddPropertyWithCorrectSeller() { // Arrange const string sellerUserId = "123"; var command = new CreatePropertyCommand { SellerUserId = sellerUserId }; // Act _handler.Handle(command); // Assert _context.Properties.Received(1).Add(Arg.Is <Models.Property>(x => x.SellerUserId == sellerUserId)); }
public async Task <ApiResult> CreateProperty([FromBody] CreatePropertyCommand request) { return(await _sender.Send(request)); }
public async Task <ActionResult <int> > Create(CreatePropertyCommand command) { return(await Mediator.Send(command)); }