Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        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());
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public async Task <IActionResult> Register(AddPropertyCommand command)
        {
            var response = await mediator.Send(command);

            if (response)
            {
                return(Ok());
            }

            return(BadRequest());
        }
Esempio n. 5
0
        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());
        }
Esempio n. 6
0
        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());
        }
Esempio n. 7
0
        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());
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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());
        }
Esempio n. 10
0
        public async Task <BaseDto> AddPropertyHandler([FromBody] AddPropertyCommand cmd)
        {
            var cmdResponse = await _mediator.Send(cmd);

            return(cmdResponse);
        }