Beispiel #1
0
        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>()));
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        public ActionResult Create(CreatePropertyCommand command)
        {
            var handler = new CreatePropertyCommandHandler(_context);

            command.SellerUserId = User.Identity.GetUserId();

            handler.Handle(command);

            return(RedirectToAction("MyProperties"));
        }
Beispiel #4
0
        public async Task <IActionResult> AddAsset([FromBody] CreatePropertyCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(400));
            }

            var result = await _mediator.Send(command);

            return(Ok(result));
        }
Beispiel #5
0
        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());
            }
        }
Beispiel #7
0
        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"));
        }
Beispiel #8
0
        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));
        }
Beispiel #9
0
        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."));
        }
Beispiel #10
0
        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"));
        }
Beispiel #11
0
        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());
            }
        }
Beispiel #13
0
        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));
 }