public async Task BoundaryTestFor_ValidBuyerId()
        {
            //mocking
            _mockCollection.Setup(op => op.InsertOneAsync(_buyer, null,
                                                          default(CancellationToken))).Returns(Task.CompletedTask);
            _mockContext.Setup(c => c.GetCollection <Buyer>(typeof(Buyer).Name)).Returns(_mockCollection.Object);

            //Craetion of new Db
            _mockOptions.Setup(s => s.Value).Returns(settings);
            var context  = new MongoDBContext(_mockOptions.Object);
            var userRepo = new BuyerServices(context);
            var res      = false;
            //Act
            await userRepo.RegisterAsync(_buyer);

            var result = await userRepo.GetBuyerByIdAsync(_buyer.BuyerId);

            Assert.InRange(_buyer.BuyerId.Length, 20, 30);

            //writing tset boolean output in text file, that is present in project directory
            if (result.BuyerId.Length.ToString() == _buyer.BuyerId.Length.ToString())
            {
                res = true;
            }
            File.AppendAllText("../../../../output_boundary_revised.txt", "BoundaryTestFor_ValidBuyerId=" + res + "\n");
        }
        public async Task BoundaryTestFor_ValidBuyerName()
        {
            //mocking
            _mockCollection.Setup(op => op.InsertOneAsync(_buyer, null,
                                                          default(CancellationToken))).Returns(Task.CompletedTask);
            _mockContext.Setup(c => c.GetCollection <Buyer>(typeof(Buyer).Name)).Returns(_mockCollection.Object);

            //Craetion of new Db
            _mockOptions.Setup(s => s.Value).Returns(settings);
            var context  = new MongoDBContext(_mockOptions.Object);
            var userRepo = new BuyerServices(context);

            //Act
            await userRepo.RegisterAsync(_buyer);

            var result = await userRepo.GetBuyerByIdAsync(_buyer.BuyerId);



            bool getisUserName = Regex.IsMatch(result.FirstName, @"^[a-zA-Z0-9]{4,10}$", RegexOptions.IgnoreCase);
            bool isUserName    = Regex.IsMatch(_buyer.FirstName, @"^[a-zA-Z0-9]{4,10}$", RegexOptions.IgnoreCase);

            //writing tset boolean output in text file, that is present in project directory
            File.AppendAllText("../../../../output_boundary_revised.txt", "BoundaryTestFor_ValidBuyerName=" + isUserName.ToString() + "\n");
            //Assert
            Assert.True(isUserName);
            Assert.True(getisUserName);
        }
        public void TestAddToCart()
        {
            //Arrange - Create some test products
            Product Product = new Product()
            {
                Id            = 1,
                ProductName   = "Apple Mobile",
                SubCategoryId = "1",
                Price         = 2000,
                BuyerId       = 1,
                CategoryId    = "1"
            };

            Buyer buyer = new Buyer();

            buyer.Id = 1;


            List <Product> itemlist = new List <Product>();

            itemlist.Add(Product);


            BuyerServices buyerservice = new BuyerServices();


            //Act

            var result = buyerservice.AddToCart(itemlist, buyer.Id);

            //Assert

            Assert.Contains(true, itemlist);
        }
        public async Task BoundaryTestFor_ValidBuyerEmail()
        {
            //mocking
            _mockCollection.Setup(op => op.InsertOneAsync(_buyer, null,
                                                          default(CancellationToken))).Returns(Task.CompletedTask);
            _mockContext.Setup(c => c.GetCollection <Buyer>(typeof(Buyer).Name)).Returns(_mockCollection.Object);

            //Craetion of new Db
            _mockOptions.Setup(s => s.Value).Returns(settings);
            var context  = new MongoDBContext(_mockOptions.Object);
            var userRepo = new BuyerServices(context);

            //Act
            await userRepo.RegisterAsync(_buyer);

            var result = await userRepo.GetBuyerByIdAsync(_buyer.BuyerId);

            //Action
            bool CheckEmail = Regex.IsMatch(result.Email, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);
            bool isEmail    = Regex.IsMatch(_buyer.Email, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);

            //writing tset boolean output in text file, that is present in project directory
            File.AppendAllText("../../../../output_boundary_revised.txt", "BoundaryTestFor_ValidBuyerEmail=" + isEmail.ToString() + "\n");

            //Assert
            Assert.True(isEmail);
            Assert.True(CheckEmail);
        }
        public async Task TestFor_GetBuyerByIdAsync()
        {
            //Arrange
            //mocking
            var res = false;

            _mockCollection.Setup(op => op.FindSync(It.IsAny <FilterDefinition <Buyer> >(),
                                                    It.IsAny <FindOptions <Buyer, Buyer> >(),
                                                    It.IsAny <CancellationToken>()));
            _mockContext.Setup(c => c.GetCollection <Buyer>(typeof(Buyer).Name));

            //Craetion of new Db
            _mockOptions.Setup(s => s.Value).Returns(settings);
            var context  = new MongoDBContext(_mockOptions.Object);
            var userRepo = new BuyerServices(context);

            //Act
            await userRepo.RegisterAsync(_buyer);

            var result = await userRepo.GetBuyerByIdAsync(_buyer.BuyerId);

            //Assert
            Assert.NotNull(result);

            //writing tset boolean output in text file, that is present in project directory
            if (result != null)
            {
                res = true;
            }
            File.AppendAllText("../../../../output_revised.txt", "TestFor_GetBuyerByIdAsync=" + res + "\n");
        }
Beispiel #6
0
        public async Task BoundaryTestFor_ValidBuyerPhoneNumberLength()
        {
            //mocking
            _mockCollection.Setup(op => op.InsertOneAsync(_buyer, null,
                                                          default(CancellationToken))).Returns(Task.CompletedTask);
            _mockContext.Setup(c => c.GetCollection <Buyer>(typeof(Buyer).Name)).Returns(_mockCollection.Object);

            //Craetion of new Db
            _mockOptions.Setup(s => s.Value).Returns(settings);
            var context  = new MongoDBContext(_mockOptions.Object);
            var userRepo = new BuyerServices(context);

            //Act
            await userRepo.RegisterAsync(_buyer);

            var result = await userRepo.GetBuyerByIdAsync(_buyer.BuyerId);

            var MinLength = 10;
            var MaxLength = 10;

            //Action
            var actualLength = _buyer.PhoneNumber.ToString().Length;

            File.AppendAllText("../../../../output_boundary_revised.txt", "BoundaryTestFor_ValidBuyerPhoneNumberLength=" + actualLength + "\n");

            //Assert
            Assert.InRange(result.PhoneNumber.ToString().Length, MinLength, MaxLength);
            Assert.InRange(actualLength, MinLength, MaxLength);
        }
        public async void TestFor_BuyerRegisterAsync()
        {
            //mocking
            var res = false;

            _mockCollection.Setup(op => op.InsertOneAsync(_buyer, null,
                                                          default(CancellationToken))).Returns(Task.CompletedTask);
            _mockContext.Setup(c => c.GetCollection <Buyer>(typeof(Buyer).Name)).Returns(_mockCollection.Object);

            _mockOptions.Setup(s => s.Value).Returns(settings);
            var context  = new MongoDBContext(_mockOptions.Object);
            var userRepo = new BuyerServices(context);

            //Action
            var buyer = await userRepo.RegisterAsync(_buyer);

            //Assert
            Assert.NotNull(buyer);
            Assert.Equal(_buyer.FirstName, buyer.FirstName);

            //writing tset boolean output in text file, that is present in project directory
            if (buyer != null)
            {
                res = true;
            }
            File.AppendAllText("../../../../output_revised.txt", "TestFor_BuyerRegisterAsync=" + res + "\n");
        }
        public async Task ExceptionTestFor_InValidBuyerLogin()
        {
            _mockOptions.Setup(s => s.Value).Returns(settings);
            var context   = new MongoDBContext(_mockOptions.Object);
            var buyerRepo = new BuyerServices(context);
            //Action
            //Assert
            var ex = await Assert.ThrowsAsync <UserNotFoundException>(() => buyerRepo.Login(_buyer));

            Assert.Equal("User Not Found", ex.Messages);
        }
        public async void CreateNewBuyer_Null_Failure()
        {
            // Arrange
            _buyer = null;

            //Act
            var bookRepo = new BuyerServices(_mockContext.Object);

            // Assert
            var create = bookRepo.RegisterAsync(_buyer);

            File.AppendAllText("../../../../output_exception_revised.txt", "CreateNewBuyer_Null_Failure=true");
            //await Assert.ThrowsAsync<ArgumentNullException>(() => create);
        }
        //[ExpectedException(typeof(EMartExecetion))]
        public void TestExceptionSearchItems()
        {
            //Arrange
            string ProductName  = "tv";
            string CategoryName = "Electrical";
            string Subcategory  = "sub";

            //Action
            BuyerServices buyerService = new BuyerServices();

            //Assert
            var ex = Assert.Throws <ProductNotFoundException>(() => buyerService.SearchProduct(ProductName, CategoryName, Subcategory));

            Assert.AreEqual("Item is Not found in stock", ex.Message);
        }
Beispiel #11
0
        public async void CreateNewBuyer_Null_Failure()
        {
            // Arrange
            _buyer = null;
            var res = true;
            //Act
            var bookRepo = new BuyerServices(_mockContext.Object);

            // Assert
            var create = bookRepo.RegisterAsync(_buyer);

            await Assert.ThrowsAsync <ArgumentNullException>(() => create);

            if (create.IsCompletedSuccessfully)
            {
                res = false;
            }
            //writing tset boolean output in text file, that is present in project directory
            File.AppendAllText("../../../../output_exception_revised.txt", "CreateNewBuyer_Null_Failure=" + res + "\n");
        }
        public async Task TestFor_GetAllBuyersAsync()
        {
            //Arrange
            var res = false;
            Mock <IAsyncCursor <Buyer> > _userCursor = new Mock <IAsyncCursor <Buyer> >();

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

            _mockCollection.Setup(op => op.FindSync(It.IsAny <FilterDefinition <Buyer> >(),
                                                    It.IsAny <FindOptions <Buyer, Buyer> >(),
                                                    It.IsAny <CancellationToken>())).Returns(_userCursor.Object);
            _mockContext.Setup(c => c.GetCollection <Buyer>(typeof(Buyer).Name)).Returns(_mockCollection.Object);
            _mockOptions.Setup(s => s.Value).Returns(settings);
            var context  = new MongoDBContext(_mockOptions.Object);
            var userRepo = new BuyerServices(context);
            //Action
            var result = await userRepo.GetAllBuyersAsync();

            //Assert
            foreach (Buyer user in result)
            {
                Assert.NotNull(user);
                break;
            }

            //writing tset boolean output in text file, that is present in project directory
            if (result != null)
            {
                res = true;
            }
            File.AppendAllText("../../../../output_revised.txt", "TestFor_GetAllBuyersAsync=" + res + "\n");
        }
 public FunctionalTest()
 {
     _Buyerservice  = new BuyerServices(_session);
     _Sellerservice = new SellerServices(_session);
 }
Beispiel #14
0
 public BoundaryTest()
 {
     _Buyerservice  = new BuyerServices(_session);
     _Sellerservice = new SellerServices(_session);
 }
 public ExceptionTest()
 {
     _Buyerservice  = new BuyerServices(_session);
     _Sellerservice = new SellerServices(_session);
 }