Exemple #1
0
        public IHttpActionResult DeleteOrganizationProperty(int id)
        {
            try
            {
                UnitOfWork unitOfWork = new UnitOfWork(factory);

                OrganizationProperty organizationProperty = unitOfWork.OrganizationPropertiesRepository
                                                            .Get(d => d.Id == id).FirstOrDefault();
                organizationProperty.Deleted = true;
                unitOfWork.OrganizationPropertiesRepository.Update(organizationProperty);
                unitOfWork.Save();
                return(Ok(organizationProperty.ToDTO()));
            }
            catch (NotFoundException nfe)
            {
                return(NotFound());
            }
            catch (ConflictException ce)
            {
                return(Conflict());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemple #2
0
        public void PutDocument_ShouldReturnOk()
        {
            var propertiesTestData = new List <OrganizationProperty>()
            {
                new OrganizationProperty {
                    Id = 1, OrganizationId = 2
                },
                new OrganizationProperty {
                    Id = 2, Deleted = true, OrganizationId = 2
                },
                new OrganizationProperty {
                    Id = 3, OrganizationId = 3
                }
            };
            var properties = MockHelper.MockDbSet(propertiesTestData);

            properties.Setup(d => d.Find(It.IsAny <object>())).Returns <object[]>((keyValues) => { return(properties.Object.SingleOrDefault(product => product.Id == (int)keyValues.Single())); });
            properties.Setup(d => d.Add(It.IsAny <OrganizationProperty>())).Returns <OrganizationProperty>((contact) =>
            {
                propertiesTestData.Add(contact);
                properties = MockHelper.MockDbSet(propertiesTestData);
                return(contact);
            });


            var typesTestData = new List <OrganizationPropertyType>()
            {
                new OrganizationPropertyType {
                    Id = 1, CountryId = 1
                },
                new OrganizationPropertyType {
                    Id = 2, CountryId = 1
                },
                new OrganizationPropertyType {
                    Id = 3, CountryId = 2
                }
            };
            var types = MockHelper.MockDbSet(typesTestData);

            var orgsTestData = new List <Organization>()
            {
                new Organization {
                    CountryId = 1
                }
            };
            var orgs = MockHelper.MockDbSet(orgsTestData);



            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.OrganizationProperties).Returns(properties.Object);
            dbContext.Setup(d => d.Set <OrganizationProperty>()).Returns(properties.Object);

            dbContext.Setup(m => m.Organizations).Returns(orgs.Object);
            dbContext.Setup(d => d.Set <Organization>()).Returns(orgs.Object);

            dbContext.Setup(m => m.OrganizationPropertyTypes).Returns(types.Object);
            dbContext.Setup(d => d.Set <OrganizationPropertyType>()).Returns(types.Object);

            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);

            OrganizationProperty passport = new OrganizationProperty {
                Id = 3, OrganizationId = 3
            };
            var controller = new OrganizationPropertiesController(factory.Object);
            var result     = controller.PutOrganizationProperty(3, passport.ToDTO()) as OkNegotiatedContentResult <OrganizationPropertyDTO>;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Content.Id);
        }
Exemple #3
0
        public void PostProperty_ShoulAddProperty()
        {
            var propertiesTestData = new List <OrganizationProperty>()
            {
                new OrganizationProperty {
                    Id = 1, OrganizationId = 2
                },
                new OrganizationProperty {
                    Id = 2, Deleted = true, OrganizationId = 2
                },
                new OrganizationProperty {
                    Id = 3, OrganizationId = 3
                }
            };
            var properties = MockHelper.MockDbSet(propertiesTestData);

            properties.Setup(d => d.Find(It.IsAny <object>())).Returns <object[]>((keyValues) => { return(properties.Object.SingleOrDefault(product => product.Id == (int)keyValues.Single())); });
            properties.Setup(d => d.Add(It.IsAny <OrganizationProperty>())).Returns <OrganizationProperty>((contact) =>
            {
                propertiesTestData.Add(contact);
                properties = MockHelper.MockDbSet(propertiesTestData);
                return(contact);
            });


            var typesTestData = new List <OrganizationPropertyType>()
            {
                new OrganizationPropertyType {
                    Id = 1, CountryId = 1
                },
                new OrganizationPropertyType {
                    Id = 2, CountryId = 1
                },
                new OrganizationPropertyType {
                    Id = 3, CountryId = 2
                }
            };
            var types = MockHelper.MockDbSet(typesTestData);

            var orgsTestData = new List <Organization>()
            {
                new Organization {
                    CountryId = 1
                }
            };
            var orgs = MockHelper.MockDbSet(orgsTestData);



            var dbContext = new Mock <IAppDbContext>();

            dbContext.Setup(m => m.OrganizationProperties).Returns(properties.Object);
            dbContext.Setup(d => d.Set <OrganizationProperty>()).Returns(properties.Object);

            dbContext.Setup(m => m.Organizations).Returns(orgs.Object);
            dbContext.Setup(d => d.Set <Organization>()).Returns(orgs.Object);

            dbContext.Setup(m => m.OrganizationPropertyTypes).Returns(types.Object);
            dbContext.Setup(d => d.Set <OrganizationPropertyType>()).Returns(types.Object);


            dbContext.Setup(d => d.ExecuteStoredProcedure <int>(It.IsAny <string>(), It.IsAny <object[]>()))
            .Returns <string, object[]>((query, parameters) =>
            {
                List <int> list = new List <int>();
                if (query.Contains("NewTableId"))
                {
                    int i = properties.Object.Max(d => d.Id) + 1;
                    list.Add(i);
                }
                else
                {
                    list.Add(0);
                }
                return(list);
            });

            var factory = new Mock <IDbContextFactory>();

            factory.Setup(m => m.CreateDbContext()).Returns(dbContext.Object);
            OrganizationProperty passport = new OrganizationProperty {
                Id = 0, OrganizationId = 3
            };
            var controller = new OrganizationPropertiesController(factory.Object);
            var result     = controller.PostOrganizationProperty(passport.ToDTO()) as CreatedAtRouteNegotiatedContentResult <OrganizationPropertyDTO>;

            Assert.IsNotNull(result);
            Assert.AreEqual(4, result.Content.Id);
            Assert.AreEqual(3, result.Content.OrganizationId);
        }