Beispiel #1
0
 public ObjectId AddCorporation(Corporation build)
 {
     build.Id = ObjectId.GenerateNewId();
     _corporation.Insert(build);
     WriteConcernResult x = new WriteConcernResult(response: build.ToBsonDocument());
     return build.Id;
 }
 public void Init()
 {
     _fm = new FilterManager();
     _cp = new Corporation() {
         Id = ObjectId.Parse("564db26db99f725971d81657"),
         Name = "EvilCorp",
         Nation = "Italy",
         RealEstates = new List<RealEstate>()
         {
             new RealEstate() {
                 code = 1,
                 state = "Ungar",
                 street = "noob"
             },
             new RealEstate() {
                 code = 2,
                 state = "italy",
                 zip = 123
             },
             new RealEstate(){ },
             new RealEstate() {
             code = 3,
             street = "ciao",
             state = "canad",
             zip = 12312,
             city = "sanfelicepaninaro"
             },
             new RealEstate(){ code = 2 },
         }
     };
 }
 public void Init()
 {
     _repositoryMock = new Mock<IRepository>();
     _addCorporationManager = new AddCorporationManager();
     _cp = new Corporation { Name = "Telecom", Nation = "Austria" } ;
     _repositoryMock.Setup(x => x.AddCorporation(It.IsAny<Corporation>())).Returns(
                         new ObjectId("564db26db99f725971d81657"));
 }
        //Work In Progress
        public List<RealEstate> FilterRealEstates(Corporation cp, RealEstate re)
        {
            List<RealEstate> resultList = new List<RealEstate>();

            foreach (var item in cp.RealEstates)
            {
                bool ToAdd = true;

                if (ToAdd && re.code != 0)
                { if (!item.code.Equals(re.code)) ToAdd = false; }

                if (ToAdd && re.zip != 0)
                { if (!item.zip.Equals(re.zip)) ToAdd = false; }

                if (ToAdd && !String.IsNullOrWhiteSpace(re.city))
                {
                    if (item.city == null)
                    {
                        ToAdd = false;
                    }
                    else
                        if (!item.city.ToLower().Contains(re.city.ToLower())) ToAdd = false;
                }

                if (ToAdd && !String.IsNullOrWhiteSpace(re.state))
                {
                    if (item.state == null)
                    {
                        ToAdd = false;
                    }
                    else
                        if (!item.state.ToLower().Contains(re.city.ToLower())) ToAdd = false;
                }

                if (ToAdd && !String.IsNullOrWhiteSpace(re.street))
                {
                    if (item.street == null)
                    {
                        ToAdd = false;
                    }
                    else
                        if (!item.street.ToLower().Contains(re.street.ToLower())) ToAdd = false;
                }

                if (ToAdd == true)
                {
                    resultList.Add(item);
                }
            }

            return resultList;
        }
        public void FilterCorporation_SubStringTest(string name, string nation, bool expected)
        {
            _cp = new Corporation() { Name = name, Nation = nation };

            var res = _fm.FilterCorporation(_listCorp, _cp);

            if (res.Count == 0)
            {
                Assert.AreEqual(expected, false);
            }
            else
                Assert.AreEqual(expected, res.First().Name == "MacDonato");
        }
 public List<Corporation> FilterCorporation(List<Corporation> cpList, Corporation cp)
 {
     List<Corporation> cpSearched;
     if (!string.IsNullOrEmpty(cp.Name) && !string.IsNullOrEmpty(cp.Nation))
     {
         cpSearched = cpList.Where(x => x.Name.ToLower().Contains(cp.Name.ToLower())
         && x.Nation.ToLower().Contains(cp.Nation.ToLower())).ToList();
         return cpSearched;
     }
     else if (string.IsNullOrEmpty(cp.Nation))
     {
         cpSearched = cpList.Where(x => x.Name.ToLower().Contains(cp.Name.ToLower())).ToList();
         return cpSearched;
     }
     else
     {
         cpSearched = cpList.Where(x => x.Nation.ToLower().Contains(cp.Nation.ToLower())).ToList();
         return cpSearched;
     }
 }
Beispiel #7
0
        public bool UpdateCorporation(string Id, Corporation build)
        {
            var _id = ObjectId.Parse(Id);
            IMongoQuery query = Query.EQ("_id", _id);
            IMongoUpdate update = Update
                .Set("_id", _id)
                .Set("Name", build.Name)
                .Set("Nation", build.Nation);

            _corporation.Update(query, update);

               //MANCA LA GESTIONE DELL'ERRORE --- DA FARE
            //WriteConcernResult x = new WriteConcernResult(response: build.ToBsonDocument());
            //if (x.HasLastErrorMessage)
            //    return false;

            return true;
        }
 public bool UpdateCorporation(IRepository repository, string id, Corporation corporation)
 {
     return repository.UpdateCorporation(id, corporation);
 }
 public ObjectId AddCorporation(IRepository repository, Corporation corporation)
 {
     return repository.AddCorporation(corporation);
 }
        public void UpdateCorporation_ShouldReturnCorporationUpdated()
        {
            ObjectId id = ObjectId.Parse("564db279b99f725971d81658");
            string Name = "MockNameUpdated";
            var cor = _corpoList.Find(x => x.Id == id);
            IMongoQuery query = Query.EQ("_id", id);
            using (TransactionScope ts = new TransactionScope())
            {
                IMongoUpdate update = Update
                    .Set("_id", id)
                    .Set("Name", Name)
                    .Set("Nation", cor.Nation);

                Corporation ToUpdate = new Corporation
                {
                    Id = cor.Id,
                    Name = Name,
                    Nation = cor.Nation
                };
                _corporations.Update(query, update);
                _repositoryMock.Object.UpdateCorporation(id.ToString(), ToUpdate);

                Assert.AreEqual(true, ToUpdate.Name == Name);

            }
        }
        public void SetUp()
        {
            string connection = "mongodb://localhost:27017";
            _client = new MongoClient(connection);
            _server = _client.GetServer();
            _database = _server.GetDatabase("local", WriteConcern.Unacknowledged);
            _corporations = _database.GetCollection<Corporation>("Corporations");

            var corpo = new Corporation
            {

                Id = ObjectId.Parse("564db279b99f725971d81658"),
                Name = "MockNome",
                Nation = "MockNation",
                RealEstates = new List<RealEstate>()
                    {
                        new RealEstate()
                        {
                            city = "MockCity",
                            code = 123,
                            state = "MockState",
                            street = "MockStreet",
                            zip = 123
                        }
                    }

            };

            _corpoList = new List<Corporation>()
            {
                //new Corporation()
                //{
                //    Id = ObjectId.Parse("564db279b99f725971d81658"),
                //    Name = "MockNome",
                //    Nation = "MockNation",
                //    RealEstates = new List<RealEstate>()
                //    {
                //        new RealEstate()
                //        {
                //            city = "MockCity",
                //            code = 123,
                //            state = "MockState",
                //            street = "MockStreet",
                //            zip = 123
                //        }
                //    }
                //},
                new Corporation()
                {
                    Id = ObjectId.GenerateNewId(),
                    Name = "MockNome2",
                    Nation="MockNation2",
                    RealEstates = new List<RealEstate>()
                    {
                        new RealEstate()
                        {
                            city = "MockCity2",
                            code=456,
                            state="MockState2",
                            street="MockStreet2",
                            zip=456
                        }
                    }
                }
            };
            _corpoList.Add(corpo);

            _repositoryMock = new Mock<IRepository>();

            _repositoryMock.Setup(x => x.AddCorporation(It.IsAny<Corporation>())).Returns(new ObjectId("564db279b99f725971d81658"));

            _repositoryMock.Setup(x => x.AddRealEstate(It.IsAny<string>(), It.IsAny<RealEstate>()))
                //.Returns(new RealEstate());
                .Returns(true);

            _repositoryMock.Setup(x => x.GetAllCorporations()).Returns(_corpoList);

            _repositoryMock.Setup(x => x.GetCorporation(It.IsAny<ObjectId>())).Returns(_corpoList.Find(x => x.Id == corpo.Id));

            _repositoryMock.Setup(x => x.GetCorporation(It.IsAny<string>()))
                .Returns(_corpoList.Find(x => x.Id == corpo.Id));

            _repositoryMock.Setup(x => x.RemoveCorporation(It.IsAny<string>()));

            _repositoryMock.Setup(x => x.UpdateCorporation(It.IsAny<string>(), It.IsAny<Corporation>()))
                .Returns(true);

            _filterManager = new Mock<IFilterManager>();

            _filterManager.Setup(x => x.FilterCorporation(It.IsAny<List<Corporation>>(), It.IsAny<Corporation>()))
                .Returns(It.IsAny<List<Corporation>>());

            _filterManager.Setup(x => x.FilterRealEstates(It.IsAny<Corporation>(), It.IsAny<RealEstate>()))
                .Returns(It.IsAny<List<RealEstate>>());

            _filterAddManager = new Mock<IAddCorporationManager>();

            _filterAddManager.Setup(x => x.AddCorporation(It.IsAny<IRepository>(), It.IsAny<Corporation>()))
                .Returns(new ObjectId("564db279b99f725971d81658"));

            _filterAddManager.Setup(
                x => x.AddRealEstate(It.IsAny<IRepository>(), It.IsAny<string>(), It.IsAny<RealEstate>()))
                .Returns(true);

            _filterAddManager.Setup(
                x => x.UpdateCorporation(It.IsAny<IRepository>(), It.IsAny<string>(), It.IsAny<Corporation>()))
                .Returns(true);

            _filterAddManager.Setup(
                x =>
                    x.UpdateRealEstate(It.IsAny<IRepository>(), It.IsAny<string>(), It.IsAny<int>(),
                        It.IsAny<RealEstate>()))
                .Returns(true);
        }
        public void DeleteCorporation_ShouldDeleteOneCorporation()
        {
            var count = _repositoryMock.Object.GetAllCorporations().Count();
            var corporation = new Corporation
            {
                Id = ObjectId.Parse("564db279b99f725971d12345"),
                Name = "MockToBeDeleted",
                Nation = "MockToBeDeleted"
            };
            _repositoryMock.Object.AddCorporation(corporation);
            _repositoryMock.Object.RemoveCorporation("564db279b99f725971d12345");

            var afterRemove = _repositoryMock.Object.GetAllCorporations().Count();
            Assert.AreEqual(afterRemove, count);
        }