Beispiel #1
0
        public void Lisr_GetViewFilterByPriceAndOrderedByName_ItsOkViewContanesListOfAdvertisementsFilteredByPriceAndOrderedByName(
            [Values(Sort.Name)] Sort sort,
            [Values((uint)252)] uint minPrice,
            [Values((uint)1515)] uint maxPrice)
        {
            var controller = new AdvertisementsController();

            var result = controller.List(sort, minPrice, maxPrice);

            var advertisements = ((result as ViewResult).Model as AdvertisementsListPage).Advertisements;

            if (advertisements.Any(adv => adv.Price < minPrice))
            {
                Assert.Fail("Цены отфильтрованых объявлений должны быть болше минимума.");
            }
            if (advertisements.Any(adv => adv.Price > maxPrice))
            {
                Assert.Fail("Цены отфильтрованых объявлений должны быть меньше максимума.");
            }
            Advertisement backAdvertisment = null;

            foreach (var adv in advertisements)
            {
                if (backAdvertisment != null && adv.Name.CompareTo(backAdvertisment.Name) == -1)
                {
                    Assert.Fail("Список объявлений должен быть отсортирован по заголовку.");
                }
                backAdvertisment = adv;
            }
        }
        public async void AddAdNegative()
        {
            // Arrange
            var adServiceMock = new Mock <IAdvertisementService>();

            adServiceMock
            .Setup(a =>
                   a.AddAdvertisement(It.IsAny <int>(), It.IsAny <AdvertisementSaveDto>()))
            .ReturnsAsync(new OperationResult()
            {
                IsSuccessful  = false,
                IsClientError = true
            })
            .Verifiable();
            var userServiceMock = new Mock <IUserService>();

            userServiceMock.Setup(u => u.GetUserIdByLogin(It.IsAny <string>())).ReturnsAsync(1);

            var controller = new AdvertisementsController(adServiceMock.Object, userServiceMock.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = _fixture.User
                }
            };

            // Act
            var result = await controller.AddAd(_fixture.NewAdd);

            // Assert
            adServiceMock.Verify();
            Assert.IsType <BadRequestObjectResult>(result);
        }
Beispiel #3
0
        public void Create_GetView_ItsOkViewModelIsCreateAdvertisementView()
        {
            var controller = new AdvertisementsController();

            var result = controller.Create();

            Assert.IsInstanceOf <ViewResult>(result);
            Assert.IsInstanceOf <CreateAdvertisementView>((result as ViewResult).Model);
        }
Beispiel #4
0
        public void Save_SetFailAdv_ItsOkReturnCreatePage()
        {
            var controller = new AdvertisementsController();

            var advertisementView = new CreateAdvertisementView();

            advertisementView.Price = "-1";
            var result = controller.Save(advertisementView);

            Assert.IsInstanceOf <CreateAdvertisementView>((result as ViewResult).Model);
        }
Beispiel #5
0
        public void List_GetView_ItsOkViewModelIsAdvertisementsListPagew(
            [Values(Sort.Name, Sort.Price, Sort.PublishDate)] Sort sort,
            [Values((uint)0, uint.MaxValue, (uint)3)] uint minPrice,
            [Values((uint)0, uint.MaxValue, (uint)6437)] uint maxPrice)
        {
            var controller = new AdvertisementsController();

            var result = controller.List(sort, minPrice, maxPrice);

            Assert.IsInstanceOf <ViewResult>(result);
            Assert.IsInstanceOf <AdvertisementsListPage>((result as ViewResult).Model);
        }
Beispiel #6
0
        public void List_GetView_ItsOkViewContanesListOfAdvertisements(
            [Values(Sort.Name, Sort.Price, Sort.PublishDate)] Sort sort)
        {
            var controller = new AdvertisementsController();

            var result = controller.List(sort);

            var advertisements = ((result as ViewResult).Model as AdvertisementsListPage).Advertisements;

            if (!advertisements.Any())
            {
                Assert.Fail("Действаие List должно вернуть список объявлений.");
            }
        }
Beispiel #7
0
        public override void SetData()
        {
            advertisementQuery = ServiceProvider.GetService <IAdvertisementsQuery>();
            Assert.NotNull(advertisementQuery);

            mediatR = ServiceProvider.GetService <IMediator>();
            Assert.NotNull(mediatR);

            controller = new AdvertisementsController(mediatR, advertisementQuery);
            Assert.NotNull(controller);

            data = ServiceProvider.GetService <InMemoryPersistence>();
            Assert.NotNull(data);
        }
Beispiel #8
0
        public void calculate_score_with_success()
        {
            var mediatorMock = new Mock <IMediator>();

            mediatorMock
            .Setup(m => m.Send(It.IsAny <AdvertisementCommandHandler>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(new Unit());

            var controllerWithMediatRMocked = new AdvertisementsController(mediatorMock.Object, advertisementQuery);

            var response = controllerWithMediatRMocked.CalculateScore(1);

            Assert.IsType <OkObjectResult>(response.Result);
        }
Beispiel #9
0
        public void List_GetViewFilteredByPrice_ItsOkViewContanesEmptyListOfAdvertisements(
            [Values(Sort.Name, Sort.Price, Sort.PublishDate, Sort.Name, Sort.Name)] Sort sort,
            [Values((uint)0, (uint)635, (uint)444, uint.MaxValue, uint.MaxValue)] uint minPrice,
            [Values((uint)0, (uint)134, (uint)0, uint.MinValue, uint.MaxValue)] uint maxPrice)
        {
            var controller = new AdvertisementsController();

            var result = controller.List(sort, minPrice, maxPrice);

            var advertisements = ((result as ViewResult).Model as AdvertisementsListPage).Advertisements;

            if (advertisements.Any())
            {
                Assert.Fail("Отфильтрованный список должен быть пустым.");
            }
        }
Beispiel #10
0
        public void List_GetViewDefault_ItsOkViewContanesListOfAdvertisementsOrderedByPublishDate()
        {
            var controller = new AdvertisementsController();

            var result = controller.List();

            var           advertisements   = ((result as ViewResult).Model as AdvertisementsListPage).Advertisements;
            Advertisement backAdvertisment = null;

            foreach (var adv in advertisements)
            {
                if (backAdvertisment != null && adv.PublishDate < backAdvertisment.PublishDate)
                {
                    Assert.Fail("Список объявлений должен быть отсортирован по дате публикации.");
                }
                backAdvertisment = adv;
            }
        }
Beispiel #11
0
        public void Save_SetValidAdv_ItsOkReturnListAdv()
        {
            var controller = new AdvertisementsController();

            var advertisementView = new CreateAdvertisementView()
            {
                Contacts    = "т. 5745773",
                Description = "Пример",
                Name        = "Пример",
                Price       = "1000"
            };
            var result = controller.Save(advertisementView);

            Assert.IsInstanceOf <RedirectToRouteResult>(result);

            Assert.IsTrue((result as RedirectToRouteResult).RouteValues.TryGetValue("action", "List"), "Контроллер должен быть Advertisements");
            Assert.IsTrue((result as RedirectToRouteResult).RouteValues.TryGetValue("action", "List"), "Действие должно быть List");
        }
Beispiel #12
0
        public void List_GetViewOrderedByName_ItsOkViewContanesListOfAdvertisementsOrderedBName(
            [Values(Sort.Name)] Sort sort
            )
        {
            var controller = new AdvertisementsController();

            var result = controller.List(sort);

            var           advertisements   = ((result as ViewResult).Model as AdvertisementsListPage).Advertisements;
            Advertisement backAdvertisment = null;

            foreach (var adv in advertisements)
            {
                if (backAdvertisment != null && adv.Name.CompareTo(backAdvertisment.Name) == -1)
                {
                    Assert.Fail("Список объявлений должен быть отсортирован по заголовку.");
                }
                backAdvertisment = adv;
            }
        }
Beispiel #13
0
        public void List_GetViewFilteredByPrice_ItsOkViewContanesListOfAdvertisementsFilteredByPrice(
            [Values(Sort.Name, Sort.Price, Sort.PublishDate, Sort.Name)] Sort sort,
            [Values((uint)0, (uint)0, (uint)635, (uint)635)] uint minPrice,
            [Values(uint.MaxValue, (uint)9065, uint.MaxValue, (uint)9065)] uint maxPrice)
        {
            var controller = new AdvertisementsController();

            var result = controller.List(sort, minPrice, maxPrice);

            var advertisements = ((result as ViewResult).Model as AdvertisementsListPage).Advertisements;

            if (advertisements.Any(adv => adv.Price < minPrice))
            {
                Assert.Fail("Цены отфильтрованых объявлений должны быть болше минимума.");
            }
            if (advertisements.Any(adv => adv.Price > maxPrice))
            {
                Assert.Fail("Цены отфильтрованых объявлений должны быть меньше максимума.");
            }
        }