Example #1
0
        public void Search_Should_ReturnAllAdverts_WhenAllParametersAreNull()
        {
            // Arrange
            var adverts = new List <Advert>()
            {
                new Advert {
                    Id = 1, Title = "Yolo", CityId = 1, Power = 600
                },
                new Advert {
                    Id = 2, Title = "Yolo", CityId = 5, Power = 1001
                }
            }.AsQueryable();

            var mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();

            mockedDbSet.Setup(m => m.All()).Returns(adverts);

            var mockedAdvertService = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);

            // Act
            var result = mockedAdvertService.Search(null, null, null, null, null, null, null, null, null, null);

            // Assert
            Assert.AreEqual(result, adverts);
            Assert.AreEqual(result.Count(), adverts.Count());
        }
Example #2
0
        public void Search_Should_CityParamateForExample_WhenIsValid()
        {
            // Arrange
            var adverts = new List <Advert>()
            {
                new Advert {
                    Id = 1, Title = "Yolo", CityId = 1, Power = 600
                },
                new Advert {
                    Id = 2, Title = "Yolo", CityId = 2, Power = 1001
                },
                new Advert {
                    Id = 2, Title = "Yolo", CityId = 2, Power = 1001
                }
            }.AsQueryable();

            var mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();

            mockedDbSet.Setup(m => m.All()).Returns(adverts);

            var mockedAdvertService = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);

            var result = mockedAdvertService.Search(null, 2, null, null, null, null, null, null, null, null);

            // Assert
            Assert.AreEqual(result.ToList()[0], adverts.ToList()[1]);
            Assert.AreEqual(result.ToList()[1], adverts.ToList()[2]);
            Assert.AreEqual(result.Count(), 2);
        }
Example #3
0
        public void GetAllAdvertsByUserIdShould_ShouldReturn_CorrectAdvertsAccordingToUserIdAsQueryable()
        {
            // Arrange
            string userId            = "asdasdasd";
            var    mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var    mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            var    advertService     = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);

            mockedDbSet.Setup(rep => rep.All()).Returns(() => new List <Advert>()
            {
                new Advert {
                    Id = 1, UserId = userId
                },
                new Advert {
                    Id = 2, UserId = userId
                },
                new Advert {
                    Id = 3, UserId = userId
                },
                new Advert {
                    Id = 4, UserId = userId
                }
            }.AsQueryable());

            // Act
            var result = advertService.GetAllAdvertsByUserId(userId).ToList();

            // Assert
            Assert.AreEqual(4, result.Count);
        }
Example #4
0
        public void ReturnCorrectAdverts()
        {
            // Arrange
            var expectedAdvert = new List <Advert>()
            {
                new Advert()
                {
                    Id = 1, Title = "Advert 1"
                },
                new Advert()
                {
                    Id = 2, Title = "Advert 2"
                },
                new Advert()
                {
                    Id = 3, Title = "Advert 3"
                }
            }.AsQueryable();

            var mockedAdvertRepository = new Mock <IEfDeletableRepository <Advert> >();
            var mockedEfProvider       = new Mock <IEfCarAdvertsDataProvider>();

            mockedAdvertRepository.Setup(x => x.All()).Returns(expectedAdvert);
            mockedEfProvider.Setup(p => p.Adverts).Returns(mockedAdvertRepository.Object);

            var advertService = new AdvertService(mockedEfProvider.Object);

            // Act
            var result = advertService.All();

            // Assert
            Assert.AreEqual(result, expectedAdvert);
        }
Example #5
0
        public void ReturnAllAdverts_WhenAllParametersAreNull()
        {
            // Arrange
            IQueryable <Advert> adverts = new List <Advert>()
            {
                new Advert()
                {
                    Id = 1, Title = "test 1", CityId = 1, Power = 5
                },
                new Advert()
                {
                    Id = 2, Title = "test 2", CityId = 5, Power = 7
                },
            }.AsQueryable();

            var efDeletableAdvertsRepository = new Mock <IEfDeletableRepository <Advert> >();

            efDeletableAdvertsRepository.Setup(x => x.All()).Returns(adverts);

            var mockedEfProvider = new Mock <IEfCarAdvertsDataProvider>();

            mockedEfProvider.Setup(x => x.Adverts).Returns(efDeletableAdvertsRepository.Object);

            var advertService = new AdvertService(mockedEfProvider.Object);

            // Act
            var result = advertService.Search(null, null, null, null, null, null, null, null, null, null);

            // Assert
            Assert.AreEqual(result, adverts);
            Assert.AreEqual(result.Count(), adverts.Count());
        }
Example #6
0
        public ActionResult ChooseAtributte(OgloszenieModelView adv)
        {
            ModelState.Clear();
              AdvertService srv = new AdvertService();
              var item= srv.GetAtributteForAdvert(adv);

              return View();
        }
Example #7
0
        public ProductTracker(TextView barcodeInfo, MainActivity mainActivity)
        {
            _mainActivity = mainActivity;
            _barcodeInfo  = barcodeInfo;

            var serverUrlTextbox = (EditText)mainActivity.FindViewById(Resource.Id.server_url);

            _advertService = new AdvertService(() => serverUrlTextbox.Text);
        }
        public void GetById_Should_NotBeCalled_IfNotCalledYolo()
        {
            // Arrange & Act
            var mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            var advertService     = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);

            // Assert
            mockedDbSet.Verify(rep => rep.GetById(1), Times.Never);
        }
        public void Constructor_Should_CreateAdvertServices_IfParamsAreValid()
        {
            // Arrange & Act
            var mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            var advertService     = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);

            // Assert
            Assert.That(advertService, Is.InstanceOf <AdvertService>());
        }
Example #10
0
        public Advertisement Get(int id)
        {
            AdvertService ads = new AdvertService(auth);
            Advertisement ad  = ads.GetActive().First(p => p.Id == id);

            if (ad == null)
            {
                return(null);
            }
            return(ad);
        }
        public void DeleteAdvert_Should_NotCallSaveChanges_IfAdvertIsNotDelete()
        {
            // Arrange & Act
            var mockedDbSet          = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges    = new Mock <ICarSystemEfDbContextSaveChanges>();
            var advertService        = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);
            var advertThatIsNotAdded = new Mock <Advert>();

            // Assert
            mockedSaveChanges.Verify(u => u.SaveChanges(), Times.Never);
        }
        public void ConstructorShould_ReturnNewInstanceOfAdvertService_IfParameterIsValid()
        {
            // Arrange
            var mockedEfProvider = new Mock <IEfCarAdvertsDataProvider>();

            // Act
            var advertService = new AdvertService(mockedEfProvider.Object);

            // Assert
            Assert.That(advertService, Is.Not.Null);
        }
Example #13
0
        public void DeleteAdvertById_Should_NotDeleteAdvertWithId_IfItIsNotAddedInTheFirstPlace()
        {
            // Arrange & Act
            var mockedDbSet = new Mock<IEfCarSystemDbSetCocoon<Advert>>();
            var mockedSaveChanges = new Mock<ICarSystemEfDbContextSaveChanges>();
            var advertService = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);
            var advertToDeleteWithId = new Mock<Advert>();

            // Assert
            mockedDbSet.Verify(rep => rep.Delete(advertToDeleteWithId.Object.Id), Times.Never);
        }
        public void GetById_ShouldThrowNullReferenceException_IfAdvertIsNull()
        {
            // Arrange & Act
            var           mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var           mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            var           advertService     = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);
            Mock <Advert> advertThatIsNull  = null;

            // Assert
            Assert.Throws <NullReferenceException>(() => advertService.GetById(advertThatIsNull.Object.Id));
        }
Example #15
0
        public void UpdateAdvert_Should_NotUpdateAdvertThatIsNeverUpdatedInTheFirstPlace()
        {
            // Arrange & Act
            var mockedDbSet          = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges    = new Mock <ICarSystemEfDbContextSaveChanges>();
            var advertService        = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);
            var advertThatIsNotAdded = new Mock <Advert>();

            // Assert
            mockedDbSet.Verify(rep => rep.Update(advertThatIsNotAdded.Object), Times.Never);
        }
Example #16
0
        public AdvertServiceTests()
        {
            var options = new DbContextOptionsBuilder <OurTraceDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            this.dbContext = new OurTraceDbContext(options);

            this.automapper = MapperInitializer.CreateMapper();

            this.advertService = new AdvertService(dbContext, automapper);
        }
        public void ReturnNull_IfParameterIdIsNull()
        {
            // Arrange
            var mockedEfProvider = new Mock <IEfCarAdvertsDataProvider>();

            // Act
            var advertService = new AdvertService(mockedEfProvider.Object);
            var result        = advertService.GetById(null);

            // Assert
            Assert.That(result, Is.Null);
        }
        public void AddAdvert_Should_ThrowAgrumentNullException_IfAdvertIsNull()
        {
            // Arrange
            var    mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var    mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            Advert nullAdvert        = null;

            // Act
            var advertService = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);

            // Assert
            Assert.That(() => advertService.AddAdvert(nullAdvert), Throws.ArgumentNullException);
        }
Example #19
0
        public void ThrowArgumentNullExeption_IfAdvertParameterIsNull()
        {
            // Arrange
            Advert advert = null;
            IEnumerable <HttpPostedFileBase> files = null;

            var mockedEfProvider = new Mock <IEfCarAdvertsDataProvider>();
            var advertService    = new AdvertService(mockedEfProvider.Object);

            // Act and Assert
            Assert.That(() => advertService.AddUploadedFilesToAdvert(advert, files),
                        Throws.ArgumentNullException);
        }
        public void CreateAdvert_Should_ThrowArgumentNullExeption_IfAdvertParameterIsNull()
        {
            // Arrange
            Advert advert = null;
            IEnumerable <HttpPostedFileBase> nullImages = null;
            var mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            var advertService     = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);

            // Act and Assert
            Assert.That(() => advertService.AddUploadedFilesToAdvert(advert, nullImages),
                        Throws.ArgumentNullException);
        }
        public void GetById_Should_NotReturnAdvert_IfThereIsNoAdvertYolo()
        {
            // Arrange
            var mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            var advertService     = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);

            // Act
            mockedDbSet.Setup(rep => rep.GetById(0)).Returns(() => null);

            // Assert
            Assert.IsNull(advertService.GetById(0));
        }
        public void GetAllAdverts_Should_BeCalled_IfParamsAreValid()
        {
            // Arrange
            var mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            var advertService     = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);

            // Act
            advertService.GetAllAdverts();

            // Assert
            mockedDbSet.Verify(rep => rep.All(), Times.Once);
        }
        public void GetById_Should_Work_IfCalledWithValidParams()
        {
            // Arrange
            var mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            var advertService     = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);
            var advertWithId      = new Mock <Advert>();

            // Act
            mockedDbSet.Setup(rep => rep.GetById(advertWithId.Object.Id)).Returns(() => advertWithId.Object);

            // Assert
            Assert.AreEqual(advertService.GetById(advertWithId.Object.Id), advertWithId.Object);
        }
Example #24
0
        public void UpdateAdvert_Should_BeCalled_IfAdvertIsValid()
        {
            // Arrange
            var mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            var advertService     = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);
            var advertToUpdate    = new Mock <Advert>();

            // Act
            advertService.UpdateAdvert(advertToUpdate.Object);

            // Assert
            mockedDbSet.Verify(rep => rep.Update(advertToUpdate.Object), Times.Once);
        }
        public void ThrowArgumentNullException_WhenIdParameterIsNull()
        {
            // Arrange
            var mockedAdvertRepository = new Mock <IEfDeletableRepository <Advert> >();
            var mockedEfProvider       = new Mock <IEfCarAdvertsDataProvider>();

            mockedEfProvider.Setup(p => p.Adverts).Returns(mockedAdvertRepository.Object);

            var    advertService = new AdvertService(mockedEfProvider.Object);
            Advert advert        = null;

            // Act and Assert
            Assert.Throws <ArgumentNullException>(() => advertService.Delete(advert));
        }
        public void GetById_Should_ReturnTheProperAdvertWithId_IfCalled()
        {
            // Arrange
            var mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            var advertService     = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);
            var advertWithId      = new Mock <Advert>();

            // Act
            mockedDbSet.Setup(rep => rep.GetById(advertWithId.Object.Id)).Returns(() => advertWithId.Object);

            // Assert
            Assert.IsInstanceOf <Advert>(advertService.GetById(advertWithId.Object.Id));
        }
        public void GetById_Should_ReturnTheCorrectAdvert_IfCalled()
        {
            // Arrange
            var mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            var advertService     = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);
            var advert            = new Mock <Advert>();
            var secondAdvert      = new Mock <Advert>();

            // Act
            mockedDbSet.Setup(rep => rep.GetById(advert.Object.Id)).Returns(() => advert.Object);

            // Assert
            Assert.AreNotEqual(advertService.GetById(advert.Object.Id), secondAdvert.Object);
        }
Example #28
0
        public void DeleteAdvertById_Should_CallSaveChangesTwoTimes_IfParamsAreValid()
        {
            // Arrange
            var mockedDbSet = new Mock<IEfCarSystemDbSetCocoon<Advert>>();
            var mockedSaveChanges = new Mock<ICarSystemEfDbContextSaveChanges>();
            var advertService = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);
            var advertWithId = new Mock<Advert>();

            // Act
            advertService.AddAdvert(advertWithId.Object);
            advertService.DeleteAdvertById(advertWithId.Object.Id);

            // Assert
            mockedSaveChanges.Verify(u => u.SaveChanges(), Times.Exactly(2));
        }
Example #29
0
        public void DeleteAdvertById_Should_BeCalledOnce_IfAdvertWithIdToDeleteIsValid()
        {
            // Arrange
            var mockedDbSet = new Mock<IEfCarSystemDbSetCocoon<Advert>>();
            var mockedSaveChanges = new Mock<ICarSystemEfDbContextSaveChanges>();
            var advertService = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);
            var advertToDeleteWithId = new Mock<Advert>();

            // Act
            advertService.AddAdvert(advertToDeleteWithId.Object);
            advertService.DeleteAdvertById(advertToDeleteWithId.Object.Id);

            // Assert
            mockedDbSet.Verify(rep => rep.Delete(advertToDeleteWithId.Object.Id), Times.Once);
        }
        public void DeleteAdvert_Should_BeCalledOnce_IfParamsAreValid()
        {
            // Arrange
            var mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            var advertService     = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);
            var advert            = new Mock <Advert>();

            // Act
            advertService.AddAdvert(advert.Object);
            advertService.DeleteAdvert(advert.Object);

            // Assert
            mockedDbSet.Verify(rep => rep.Delete(It.IsAny <Advert>()), Times.Once);
        }
        public void GetAllAdverts_Should_ReturnEmptyCollection_IfThereAreNoAdvertsAdded()
        {
            // Arrange
            var mockedDbSet       = new Mock <IEfCarSystemDbSetCocoon <Advert> >();
            var mockedSaveChanges = new Mock <ICarSystemEfDbContextSaveChanges>();
            var advertService     = new AdvertService(mockedDbSet.Object, mockedSaveChanges.Object);

            // Act
            IEnumerable <Advert> expectedAdvertsResult = new List <Advert>();

            mockedDbSet.Setup(rep => rep.All()).Returns(() => expectedAdvertsResult.AsQueryable());

            // Assert
            Assert.IsEmpty(advertService.GetAllAdverts());
        }
Example #32
0
        public ActionResult AddAdvert(OgloszenieModelView advert, string[] category)
        {
            AdvertService sr = new AdvertService();
             var id = Convert.ToInt16(Session["UserID"]);
             if (id == null || id==0)
             {
                 return RedirectToAction("LogIn", "Account");
             }
             advert.Id_Uzytkownika = Convert.ToInt16(Session["UserID"]);
             var _id = sr.AddAdvert(advert, category);

             advert.id = _id;
               /// return  RedirectToAction("ChooseAtributte", "Advert", new { adv = advert });
            // return RedirectToAction("ChooseAtributte", new RouteValueDictionary(advert));

             //return View("test");
             //return RedirectToAction("test");
             return RedirectToAction("test", "Advert");
             //var _url = "/Home/Index";

             //return Json(new { url = _url });
        }
Example #33
0
        public ActionResult GetAdvertByCategory(int id)
        {
            AdvertService srv = new AdvertService();

              if(id==0)
              {
                  var list = srv.GetLast100ActiveAdverts();
                  return View(list);
              }
              else
              {
                 var  list = srv.GetLast100ActiveAdvertsByCategory(id);
                 return View(list);

              }
        }