Exemplo n.º 1
0
        public async Task GetAllUsers()
        {
            //Arrange
            //Mock MoveNextAsync
            Mock <IAsyncCursor <Buyer> > _userCursor = new Mock <IAsyncCursor <Buyer> >();

            _userCursor.Setup(_ => _.Current).Returns(_list);
            _userCursor
            .SetupSequence(_ => _.MoveNext(It.IsAny <CancellationToken>()))
            .Returns(true)
            .Returns(false);

            //Mock FindSync
            _mockCollection.Setup(op => op.FindSync(It.IsAny <FilterDefinition <Buyer> >(),
                                                    It.IsAny <FindOptions <Buyer, Buyer> >(),
                                                    It.IsAny <CancellationToken>())).Returns(_userCursor.Object);

            //Mock GetCollection
            _mockContext.Setup(c => c.GetCollection <Buyer>(typeof(Buyer).Name)).Returns(_mockCollection.Object);

            //Jayanth Creating one more instance of DB

            _mockOptions.Setup(s => s.Value).Returns(settings);

            // Creating one more instance of DB
            // Passing _mockOptions instaed of _mockContext
            var context = new MongoDBContext(_mockOptions.Object);

            var userRepo = new BuyerRepository(context);

            //Act
            var result = await userRepo.GetAll();

            //Assert
            //loop only first item and assert
            foreach (Buyer user in result)
            {
                Assert.NotNull(user);
                Assert.Equal(user.FirstName, _buyer.FirstName);
                Assert.Equal(user.Email, _buyer.Email);
                break;
            }
        }
Exemplo n.º 2
0
        private void ReadFromXML_Click(object sender, RoutedEventArgs e)
        {
            List <Buyer> newBuyersList = new List <Buyer>();

            try
            {
                XDocument doc  = XDocument.Load(@"e:\Обучение\переподготовка\ч.3\курсовая\Project WPF\RealEstataeAgency\RealEstateAgency\bin\Debug\Data.xml");
                var       root = doc.Root;
                foreach (var element in root.Elements())
                {
                    var buyer = new Buyer();
                    buyer.BuyerID      = int.Parse(element.Element("id").Value);
                    buyer.BuyerName    = element.Element("name").Value;
                    buyer.BuyerAdress  = element.Element("adress").Value;
                    buyer.BuyerUNP     = int.Parse(element.Element("unp").Value);
                    buyer.BuyerPhone   = element.Element("phone").Value;
                    buyer.BuyerRequest = element.Element("request").Value;

                    newBuyersList.Add(buyer);
                }

                IBuyerRepository buyerXMLRepository = new BuyerRepository();
                foreach (var buyerRepo in buyerXMLRepository.GetAll())
                {
                    buyerXMLRepository.DeleteBuyer(buyerRepo);
                }

                foreach (var buyerXML in newBuyersList)
                {
                    buyerXMLRepository.AddBuyer(buyerXML);
                }

                UpdateSelectedBuyer();
                MessageBox.Show("Данные  импортированы");
            }
            catch (Exception ex) { MessageBox.Show("Невозможно импортировать данные."); }
        }
 public ActionResult BuyerList()
 {
     return(View(buyerRepo.GetAll()));
 }
Exemplo n.º 4
0
        public static List <string[]> Main_(string member)
        {
            List <string[]> result = new List <string[]>();

            Entity[] temp;
            switch (member)
            {
            case "Buyer":
                BuyerRepository buyer = new BuyerRepository(Global.ConnectionStringSql, Global.ProviderName);
                temp = buyer.GetAll().ToArray <Entity>();
                Buyer[] buyers = new Buyer[temp.Length];
                for (int i = 0; i < temp.Length; i++)
                {
                    buyers[i] = (Buyer)temp[i];
                }

                for (int i = 0; i < buyers.Length; i++)
                {
                    result.Add(new string[5]);
                    result[i][0] = buyers[i].Id.ToString();
                    result[i][1] = buyers[i].CreationDate.ToString();
                    result[i][2] = buyers[i].DeletedDate.ToString();
                    result[i][3] = buyers[i].Name.ToString();
                    result[i][4] = buyers[i].Surname.ToString();
                }
                break;

            case "Deal":
                DealRepository deal = new DealRepository(Global.ConnectionStringSql, Global.ProviderName);
                temp = deal.GetAll().ToArray <Entity>();
                Deal[] deals = new Deal[temp.Length];
                for (int i = 0; i < temp.Length; i++)
                {
                    deals[i] = (Deal)temp[i];
                }
                for (int i = 0; i < deals.Length; i++)
                {
                    result.Add(new string[7]);
                    result[i][0] = deals[i].Id.ToString();
                    result[i][1] = deals[i].CreationDate.ToString();
                    //result[i][2] = deals[i].DeletedDate.ToString();
                    result[i][3] = deals[i].IdBuyer.ToString();
                    result[i][4] = deals[i].IdSeller.ToString();
                    result[i][5] = deals[i].Summ.ToString();
                    result[i][6] = deals[i].Date.ToString();
                }
                break;

            case "Saller":
                SallerRepository saller = new SallerRepository(Global.ConnectionStringSql, Global.ProviderName);
                temp = saller.GetAll().ToArray <Entity>();
                Saller[] sallers = new Saller[temp.Length];
                for (int i = 0; i < temp.Length; i++)
                {
                    sallers[i] = (Saller)temp[i];
                }
                for (int i = 0; i < sallers.Length; i++)
                {
                    result.Add(new string[5]);
                    result[i][0] = sallers[i].Id.ToString();
                    result[i][1] = sallers[i].CreationDate.ToString();
                    //result[i][2] = sallers[i].DeletedDate.ToString();
                    result[i][3] = sallers[i].Name.ToString();
                    result[i][4] = sallers[i].Surname.ToString();
                }
                break;
            }

            return(result);
        }