public void ReturnProfileFormWithEmpty_WhenModelStatusIsInvalid()
        {
            // Arrange
            var mockedIndividualService   = new Mock <IIndividualService>();
            var mockedOrganizationService = new Mock <IOrganizationService>();
            var mockedMapper       = new Mock <IMapper>();
            var mockedPhotoHelper  = new Mock <IPhotoHelper>();
            var mockedUserProvider = new Mock <IUserProvider>();

            var controller = new IndividualController(
                mockedIndividualService.Object,
                mockedMapper.Object,
                mockedPhotoHelper.Object,
                mockedUserProvider.Object);

            controller.ModelState.AddModelError("test", "test");

            var model = new IndividualViewModel();

            var mockedUpload = new Mock <HttpPostedFileBase>();

            // Act & Assert
            controller
            .WithCallTo(x => x.Submit(model, mockedUpload.Object))
            .ShouldRenderView("ProfileForm");
            //.ShouldRedirectTo<AccountController>(typeof(AccountController).GetMethod("ProfileForm"))
            //.WithRouteValue("model");
        }
Пример #2
0
        public void ReturnPartialViewwithCorrectModel_WhenIsAjax()
        {
            // Arrange
            var username  = "******";
            var id        = Guid.NewGuid();
            var viewModel = new IndividualViewModel();

            viewModel.Id = id;
            var mockedIndividualService = new Mock <IIndividualService>();

            mockedIndividualService.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(new SofiaDayAndNight.Data.Models.Individual());
            mockedIndividualService.Setup(x => x.RemoveFriendship(It.IsAny <string>(), It.IsAny <Guid>())).Verifiable();
            var mockedPhotoHelper  = new Mock <IPhotoHelper>();
            var mockedUserProvider = new Mock <IUserProvider>();
            var mockedMapper       = new Mock <IMapper>();

            mockedMapper.Setup(x => x.Map <IndividualViewModel>(It.IsAny <SofiaDayAndNight.Data.Models.Individual>())).Returns(viewModel);

            var request = new Mock <HttpRequestBase>();

            request.SetupGet(x => x.Headers).Returns(
                new WebHeaderCollection()
            {
                { "X-Requested-With", "XMLHttpRequest" }
            }
                );
            var httpContext = new Mock <HttpContextBase>();

            httpContext.SetupGet(x => x.Request).Returns(request.Object);
            var principal         = new Mock <IPrincipal>();
            var controllerContext = new Mock <ControllerContext>();

            principal.SetupGet(x => x.Identity.Name).Returns(username);
            httpContext.SetupGet(x => x.User).Returns(principal.Object);
            controllerContext.SetupGet(x => x.HttpContext).Returns(httpContext.Object);

            var controller = new IndividualController(
                mockedIndividualService.Object,
                mockedMapper.Object,
                mockedPhotoHelper.Object,
                mockedUserProvider.Object);

            controller.ControllerContext = controllerContext.Object;

            //Act & Assert
            controller
            .WithCallTo(x => x.CancelFriendship(Guid.NewGuid()))
            .ShouldRenderPartialView("_IndividualInfoPartial")
            .WithModel <IndividualViewModel>(model =>
            {
                Assert.AreEqual(viewModel.Id, model.Id);
            });
        }
Пример #3
0
        public void ReturnViewWithCorrectModel_WhenUsernameMatch()
        {
            //Arrange
            var username = "******";
            var model    = new IndividualViewModel();

            model.UserName = username;

            var mockedIndividualService = new Mock <IIndividualService>();

            mockedIndividualService.Setup(x => x.GetByUsername(username))
            .Returns(new SofiaDayAndNight.Data.Models.Individual());
            mockedIndividualService.Setup(x => x.GetStatus(It.IsAny <string>(), model.Id))
            .Returns(IndividualStatus.None);

            var mockedOrganizationService = new Mock <IOrganizationService>();
            var mockedMapper = new Mock <IMapper>();

            mockedMapper.Setup(x => x.Map <IndividualViewModel>(
                                   It.IsAny <SofiaDayAndNight.Data.Models.Individual>()))
            .Returns(model);
            var mockedPhotoHelper  = new Mock <IPhotoHelper>();
            var mockedUserProvider = new Mock <IUserProvider>();

            var principal         = new Mock <IPrincipal>();
            var controllerContext = new Mock <ControllerContext>();

            principal.SetupGet(x => x.Identity.Name).Returns(username);
            controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object);

            var controller = new IndividualController(
                mockedIndividualService.Object,
                mockedMapper.Object,
                mockedPhotoHelper.Object,
                mockedUserProvider.Object);

            controller.ControllerContext = controllerContext.Object;

            //Act & Assert
            controller
            .WithCallTo(x => x.ProfileDetails(username))
            .ShouldRenderDefaultView()
            .WithModel <IndividualViewModel>(m =>
            {
                Assert.AreEqual(model.UserName, m.UserName);
                Assert.AreEqual(model.Id, m.Id);
            });
        }
Пример #4
0
        public void RedirectToCorrectAction_WhenIsNotAjax()
        {
            // Arrange
            var username = "******";
            var mockedIndividualService = new Mock <IIndividualService>();

            //mockedIndividualService.Setup(x => x.GetById(It.IsAny<Guid>())).Returns(new SofiaDayAndNight.Data.Models.Individual());
            mockedIndividualService.Setup(x => x.RemoveFriendship(It.IsAny <string>(), It.IsAny <Guid>())).Verifiable();
            var mockedPhotoHelper  = new Mock <IPhotoHelper>();
            var mockedUserProvider = new Mock <IUserProvider>();
            var mockedMapper       = new Mock <IMapper>();

            var request = new Mock <HttpRequestBase>();
            //request.SetupGet(x => x.Headers).Returns(
            //    new WebHeaderCollection() {
            //        {"X-Requested-With", "XMLHttpRequest"}
            //    }
            //);
            var httpContext = new Mock <HttpContextBase>();

            httpContext.SetupGet(x => x.Request).Returns(request.Object);
            var principal         = new Mock <IPrincipal>();
            var controllerContext = new Mock <ControllerContext>();

            principal.SetupGet(x => x.Identity.Name).Returns(username);
            httpContext.SetupGet(x => x.User).Returns(principal.Object);
            controllerContext.SetupGet(x => x.HttpContext).Returns(httpContext.Object);

            var controller = new IndividualController(
                mockedIndividualService.Object,
                mockedMapper.Object,
                mockedPhotoHelper.Object,
                mockedUserProvider.Object);

            controller.ControllerContext = controllerContext.Object;

            //Act & Assert
            controller
            .WithCallTo(x => x.CancelFriendship(Guid.NewGuid()))
            .ShouldRedirectTo(typeof(IndividualController).GetMethod("ProfileDetails"))
            .WithRouteValue("username");
        }
Пример #5
0
        public void ReturnBadRequest_WhenUsernameIsNull()
        {
            // Arrange
            var mockedIndividualService = new Mock <IIndividualService>();
            var mockedMapper            = new Mock <IMapper>();
            var mockedPhotoHelper       = new Mock <IPhotoHelper>();
            var mockedUserProvider      = new Mock <IUserProvider>();

            var controller = new IndividualController(
                mockedIndividualService.Object,
                mockedMapper.Object,
                mockedPhotoHelper.Object,
                mockedUserProvider.Object);

            //var username = "******";

            // Act & Assert
            controller
            .WithCallTo(x => x.FollowingList(null))
            .ShouldGiveHttpStatus(HttpStatusCode.BadRequest);
        }
        public void ReturnNotFoundRequest_WhenUserNotFound()
        {
            // Arrange
            var username  = "******";
            var user      = new User();
            var viewModel = new IndividualViewModel();
            var mockedIndividualService   = new Mock <IIndividualService>();
            var mockedOrganizationService = new Mock <IOrganizationService>();
            var mockedPhotoHelper         = new Mock <IPhotoHelper>();
            var mockedUserProvider        = new Mock <IUserProvider>();

            mockedUserProvider.Setup(x => x.FindByName(It.IsAny <string>())).Returns((User)null);
            mockedUserProvider.Setup(x => x.Update(user)).Verifiable();
            var mockedMapper = new Mock <IMapper>();

            mockedMapper.Setup(x => x.Map <SofiaDayAndNight.Data.Models.Individual>(It.IsAny <IndividualViewModel>()))
            .Returns(new SofiaDayAndNight.Data.Models.Individual());

            var mockedUpload = new Mock <HttpPostedFileBase>();

            var principal         = new Mock <IPrincipal>();
            var controllerContext = new Mock <ControllerContext>();

            principal.SetupGet(x => x.Identity.Name).Returns(username);
            controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object);

            var controller = new IndividualController(
                mockedIndividualService.Object,
                mockedMapper.Object,
                mockedPhotoHelper.Object,
                mockedUserProvider.Object);

            controller.ModelState.Clear();
            controller.ControllerContext = controllerContext.Object;

            //Act & Assert
            controller
            .WithCallTo(x => x.Submit(viewModel, mockedUpload.Object))
            .ShouldGiveHttpStatus(404);
        }
        public void ReturnViewWithCorrectCollection_WhenUsernameMatch()
        {
            //Arrange
            var username = "******";
            var model    = new IndividualViewModel();

            var mockedIndividualService = new Mock <IIndividualService>();

            mockedIndividualService.Setup(x => x.GetFriendsRequests(username))
            .Returns(new List <SofiaDayAndNight.Data.Models.Individual>()
            {
                new SofiaDayAndNight.Data.Models.Individual()
            });

            var mockedOrganizationService = new Mock <IOrganizationService>();
            var mockedMapper = new Mock <IMapper>();

            mockedMapper.Setup(x => x.Map <IndividualViewModel>(
                                   It.IsAny <SofiaDayAndNight.Data.Models.Individual>()))
            .Returns(model);
            var mockedPhotoHelper  = new Mock <IPhotoHelper>();
            var mockedUserProvider = new Mock <IUserProvider>();

            var controller = new IndividualController(
                mockedIndividualService.Object,
                mockedMapper.Object,
                mockedPhotoHelper.Object,
                mockedUserProvider.Object);

            //Act & Assert
            controller
            .WithCallTo(x => x.FriendsRequest(username))
            .ShouldRenderPartialView("_FriendsListPartial")
            .WithModel <IEnumerable <IndividualViewModel> >(c =>
            {
                Assert.AreEqual(1, c.Count());
                Assert.AreEqual(model.Id, c.First().Id);
            });
        }
Пример #8
0
        public void ReturnViewWithCorrectModel_WhenUsernameMatch()
        {
            //Arrange
            var username   = "******";
            var individual = new OrganizationViewModel();

            var mockedIndividualService = new Mock <IIndividualService>();

            mockedIndividualService.Setup(x => x.GetFollowingOrganization(username))
            .Returns(new List <SofiaDayAndNight.Data.Models.Organization>()
            {
                new SofiaDayAndNight.Data.Models.Organization()
            });

            var mockedMapper = new Mock <IMapper>();

            mockedMapper.Setup(x => x.Map <OrganizationViewModel>(
                                   It.IsAny <SofiaDayAndNight.Data.Models.Organization>()))
            .Returns(individual);
            var mockedPhotoHelper  = new Mock <IPhotoHelper>();
            var mockedUserProvider = new Mock <IUserProvider>();

            var controller = new IndividualController(
                mockedIndividualService.Object,
                mockedMapper.Object,
                mockedPhotoHelper.Object,
                mockedUserProvider.Object);

            //Act & Assert
            controller
            .WithCallTo(x => x.FollowingList(username))
            .ShouldRenderPartialView("_OrganizationsListPartial")
            .WithModel <IEnumerable <OrganizationViewModel> >(model =>
            {
                Assert.AreEqual(1, model.Count());
                Assert.AreEqual(individual, model.First());
            });
        }
Пример #9
0
        public void ReturnNotFoundRequest_WhenIdNotMatch()
        {
            var username = "******";
            var mockedIndividualService = new Mock <IIndividualService>();

            mockedIndividualService.Setup(x => x.GetByUsername(username)).Returns((SofiaDayAndNight.Data.Models.Individual)null);

            var mockedOrganizationService = new Mock <IOrganizationService>();
            var mockedMapper       = new Mock <IMapper>();
            var mockedPhotoHelper  = new Mock <IPhotoHelper>();
            var mockedUserProvider = new Mock <IUserProvider>();

            var controller = new IndividualController(
                mockedIndividualService.Object,
                mockedMapper.Object,
                mockedPhotoHelper.Object,
                mockedUserProvider.Object);


            // Act & Assert
            controller
            .WithCallTo(x => x.ProfileDetails(username))
            .ShouldGiveHttpStatus(404);
        }
        public void ReturnViewWithCorrectModel_WhenUsernameMatch()
        {
            //Arrange
            var username    = "******";
            var viewEvent   = new EventViewModel();
            var resultModel = new EventsListViewModel();

            resultModel.OngoingEvents = new List <EventViewModel>()
            {
                viewEvent
            };
            resultModel.UpCommingEvents = new List <EventViewModel>()
            {
                viewEvent
            };
            resultModel.PassedEvents = new List <EventViewModel>()
            {
                viewEvent
            };

            var mockedIndividualService = new Mock <IIndividualService>();

            mockedIndividualService.Setup(x => x.GetCurrentEvents(username))
            .Returns(new List <SofiaDayAndNight.Data.Models.Event>()
            {
                new SofiaDayAndNight.Data.Models.Event()
            });
            mockedIndividualService.Setup(x => x.GetPassedEvents(username))
            .Returns(new List <SofiaDayAndNight.Data.Models.Event>()
            {
                new SofiaDayAndNight.Data.Models.Event()
            });
            mockedIndividualService.Setup(x => x.GetUpcomingEvents(username))
            .Returns(new List <SofiaDayAndNight.Data.Models.Event>()
            {
                new SofiaDayAndNight.Data.Models.Event()
            });

            var mockedOrganizationService = new Mock <IOrganizationService>();
            var mockedMapper = new Mock <IMapper>();

            mockedMapper.Setup(x => x.Map <EventViewModel>(
                                   It.IsAny <SofiaDayAndNight.Data.Models.Event>()))
            .Returns(viewEvent);
            var mockedPhotoHelper  = new Mock <IPhotoHelper>();
            var mockedUserProvider = new Mock <IUserProvider>();

            var controller = new IndividualController(
                mockedIndividualService.Object,
                mockedMapper.Object,
                mockedPhotoHelper.Object,
                mockedUserProvider.Object);

            //Act & Assert
            controller
            .WithCallTo(x => x.EventsList(username))
            .ShouldRenderPartialView("_EventsListPartial")
            .WithModel <EventsListViewModel>(model =>
            {
                Assert.AreEqual(1, model.UpCommingEvents.Count());
                Assert.AreEqual(1, model.PassedEvents.Count());
                Assert.AreEqual(1, model.OngoingEvents.Count());
                Assert.AreEqual(viewEvent, model.UpCommingEvents.First());
                Assert.AreEqual(viewEvent, model.PassedEvents.First());
                Assert.AreEqual(viewEvent, model.OngoingEvents.First());
            });
        }