示例#1
0
        public ActionResult Delete(OfferViewModel model)
        {
            OfferService service = new OfferService();

            service.DeleteOffer(model.Id);
            return(RedirectToAction("Index"));
        }
示例#2
0
            public void Exception_ReturnsFalse()
            {
                // Arrange...
                dbMock.Setup(m => m.SaveChanges()).Throws <Exception>();
                var offerService = new OfferService(dbMock.Object, loggerMock.Object, productServiceMock.Object);

                // Act...
                var result = offerService.DeleteOffer(123);

                // Assert...
                Assert.False(result);
            }
示例#3
0
            public void Exception_LogsError()
            {
                // Arrange...
                dbMock.Setup(m => m.SaveChanges()).Throws <Exception>();
                var offerService = new OfferService(dbMock.Object, loggerMock.Object, productServiceMock.Object);

                // Act...
                var result = offerService.DeleteOffer(123);

                // Assert...
                loggerMock.Verify(l => l.LogError(It.IsAny <string>(), It.IsAny <Exception>()), Times.Once);
            }
示例#4
0
            public void ValidId_ReturnsTrue()
            {
                // Arrange...

                var offerService = new OfferService(dbMock.Object, loggerMock.Object, productServiceMock.Object);

                // Assert...
                var result = offerService.DeleteOffer(ExistingOfferId);

                // Act...
                Assert.True(result);
            }
示例#5
0
        public ActionResult DeleteConfirmed(int id)
        {
            _offerService.DeleteOffer(id);

            return(RedirectToAction("Index"));
        }
示例#6
0
            public void GetAllOffers()
            {
                CompanyService companyService = new CompanyService();
                OfferService   offerService   = new OfferService();

                //Get all companies
                List <Company> testCompanyList = new List <Company>();

                testCompanyList = companyService.GetAll();

                foreach (var item in testCompanyList)
                {
                    companyService.Delete(item.Id);
                }

                //Create companies and verify offer count
                Company testCompany1 = new Company();

                testCompany1.Name   = "No. One inc.";
                testCompany1.UserId = "co1" + RandomDigits();

                Company testCompany2 = new Company();

                testCompany2.Name   = "No. Two inc.";
                testCompany2.UserId = "co2" + RandomDigits();

                companyService.Save(testCompany1); //Id = 41
                companyService.Save(testCompany2); //Id = 42

                Offer testOffer11 = new Offer();

                testOffer11.Title       = "Banana peelers 5% off!";
                testOffer11.Description = "Peel yer' nanners!";
                testOffer11.Url         = "fakebananapeeler.bamazon.com/";
                testOffer11.Category    = "Kitchen Supplies";
                testOffer11.CompanyId   = testCompany1.Id;

                //Saving offers of first company(First digit = company number, second digit = offer number)
                offerService.SaveOffer(testOffer11);

                //Creating offers for second company
                Offer testOffer21 = new Offer();

                testOffer21.Title       = "Fishing Rods 10% off!";
                testOffer21.Description = "Get yer' fishin' rods here!";
                testOffer21.Url         = "fakefishingrod.bamazon.com/";
                testOffer21.Category    = "Fishing";
                testOffer21.CompanyId   = testCompany2.Id;

                Offer testOffer22 = new Offer();

                testOffer22.Title       = "Fishing bait 20% off!";
                testOffer22.Description = "We got worms here real cheap!";
                testOffer22.Url         = "fakefishingbait.bamazon.com/";
                testOffer22.Category    = "Fishing";
                testOffer22.CompanyId   = testCompany2.Id;

                //Saving offers of second company(First digit = company number, second digit = offer number)
                offerService.SaveOffer(testOffer21);
                offerService.SaveOffer(testOffer22);

                List <OfferExtended> offerList1 = new List <OfferExtended>();

                offerList1 = offerService.GetAllOffers(testCompany1.Id);//41 because id of company1 == 41
                Assert.IsTrue(offerList1.Count == 1);

                List <OfferExtended> offerList2 = new List <OfferExtended>();

                offerList2 = offerService.GetAllOffers(testCompany2.Id);
                Assert.IsTrue(offerList2.Count == 2);


                var companyList = companyService.GetAll();

                foreach (var item in companyList)
                {
                    var offerList = offerService.GetAllOffers(item.Id);
                    foreach (var item2 in offerList1)
                    {
                        offerService.DeleteOffer(item2.Id);
                    }
                    companyService.Delete(item.Id);
                }
            }
示例#7
0
            public void OfferCRUD()
            {
                // create
                var Offer           = new Offer();
                var testTitle       = "Knife Sale";
                var testDescription = "40% off these real sharp knives!";
                var testUrl         = "fakeurl.amazon.com/";
                var testCategory    = "Kitchen Supplies";
                var testCompanyId   = RandomInteger();

                Offer.Title       = testTitle;
                Offer.Description = testDescription;
                Offer.Url         = testUrl;
                Offer.Category    = testCategory;
                Offer.CompanyId   = testCompanyId;


                var OfferService = new OfferService();

                OfferService.SaveOffer(Offer);
                Assert.IsTrue(Offer.Id != 0);

                // get it, verify it's there
                var OfferId = Offer.Id;
                var Offer2  = OfferService.GetOffer(OfferId);

                Assert.IsNotNull(Offer2);

                // verify property values
                Assert.AreEqual(Offer2.Title, testTitle);
                Assert.AreEqual(Offer2.Description, testDescription);
                Assert.AreEqual(Offer2.Url, testUrl);
                Assert.AreEqual(Offer2.Category, testCategory);
                Assert.AreEqual(Offer2.CompanyId, testCompanyId);



                //// Verify that I can get by user id
                //var OfferUserId = OfferService.GetByUserId(testUserId);
                //Assert.IsNotNull(OfferUserId);

                // update it
                var testTitle2       = "Jills Offer " + RandomDigits();
                var testDescription2 = "Since no one's buying, 95% off these real sharp knives!";
                var testCategory2    = "Weapons";

                Offer2.Title       = testTitle2;
                Offer2.Description = testDescription2;
                Offer2.Category    = testCategory2;
                OfferService.SaveOffer(Offer2);


                // get it again, verify property values
                var Offer3 = OfferService.GetOffer(OfferId);

                Assert.AreEqual(testTitle2, Offer3.Title);
                Assert.AreEqual(testDescription2, Offer3.Description);
                Assert.AreEqual(testCategory2, Offer3.Category);


                // delete it
                OfferService.DeleteOffer(OfferId);
                Offer3 = OfferService.GetOffer(OfferId);
                Assert.IsNull(Offer3);
            }
示例#8
0
        public void ClaimOfferCodeCRUD()
        {
            var Offer           = new Offer();
            var testTitle       = "Necklaces";
            var testDescription = "80% off these shiny necklaces!";
            var testUrl         = "fakeurl.bamazon.necklaces/";
            var testCategory    = "Jewelry";



            var testCompanyId = RandomInteger();

            Offer.Title       = testTitle;
            Offer.Description = testDescription;
            Offer.Url         = testUrl;
            Offer.Category    = testCategory;
            Offer.CompanyId   = testCompanyId;

            //create (offercode)
            var offerCode1 = new OfferCode();

            offerCode1.Code = "ABCDEF" + RandomDigits();
            var offerCode2 = new OfferCode();

            offerCode2.Code = "GHIJKL" + RandomDigits();
            var offerCode3 = new OfferCode();

            offerCode3.Code = "MNOPQR" + RandomDigits();

            offerCode1.OfferId = Offer.Id;
            offerCode2.OfferId = Offer.Id;
            offerCode3.OfferId = Offer.Id;

            OfferService offerService = new OfferService();

            offerService.SaveOffer(Offer);
            Assert.IsTrue(Offer.Id != 0);

            offerCode1.OfferId = Offer.Id;
            offerCode2.OfferId = Offer.Id;
            offerCode3.OfferId = Offer.Id;

            offerService.SaveOfferCode(offerCode1);
            offerService.SaveOfferCode(offerCode2);
            offerService.SaveOfferCode(offerCode3);
            Assert.IsTrue(offerCode1.Id != 0);
            Assert.IsTrue(offerCode2.Id != 0);
            Assert.IsTrue(offerCode3.Id != 0);

            var userId1 = "Jackie Bolton";

            var code1 = offerService.ClaimNextCode(Offer.Id, userId1);

            Assert.IsTrue(!String.IsNullOrEmpty(code1));
            //Verify that the first code is claimed by Jackie
            offerCode1 = offerService.GetOfferCode(offerCode1.Id);
            Assert.IsTrue(offerCode1.ClaimingUser.Equals(userId1));

            var userId2 = "Sandra Lollygagger";

            var code2 = offerService.ClaimNextCode(Offer.Id, userId2);

            Assert.IsTrue(!String.IsNullOrEmpty(code2));
            //Verify that the second code is claimed by Sandra
            offerCode2 = offerService.GetOfferCode(offerCode2.Id);
            Assert.IsTrue(offerCode2.ClaimingUser.Equals(userId2));
            Assert.IsTrue(!offerCode1.ClaimingUser.Equals(offerCode2.ClaimingUser));

            var userId3 = "Kevin Spaceman";

            var code3 = offerService.ClaimNextCode(Offer.Id, userId3);

            Assert.IsTrue(!String.IsNullOrEmpty(code3));
            //Verify that the third code is claimed by Kevin
            offerCode3 = offerService.GetOfferCode(offerCode3.Id);
            Assert.IsTrue(offerCode3.ClaimingUser.Equals(userId3));
            Assert.IsTrue(!offerCode1.ClaimingUser.Equals(offerCode3.ClaimingUser));

            var userId4 = "Richmond Nocode";

            var code4 = offerService.ClaimNextCode(Offer.Id, userId4);

            //This time verifying that code4 IS empty because we have no more codes in the offer.
            Assert.IsTrue(String.IsNullOrEmpty(code4));

            offerService.DeleteOfferCode(offerCode1.Id);
            offerService.DeleteOfferCode(offerCode2.Id);
            offerService.DeleteOfferCode(offerCode3.Id);

            offerService.DeleteOffer(Offer.Id);
        }