public void CreateMakesNewChatAndIgnoresNullProperties()
        {
            var clientRepository  = RepositoryHelper.RepositoryLocalWithOneClient;
            var chatRepository    = new LocalRepository <Contact>();
            var client            = clientRepository.All().First();
            var contactService    = new Mock <IContactService>();
            var restClient        = new Mock <IRestClient>();
            var userManager       = new Mock <IIdentityMembershipProvider>();
            var contactAutoRating = new Mock <IContactAutoRating>();

            var chat = new ChatViewModel
            {
                ClientId    = client.Id,
                ClientName  = client.Name,
                Date        = new DateTime(2013, 1, 02),
                Description = "this is the description",
                LiveChatId  = "LC123456",
                Email       = "",
                Phone       = "08654321"
            };

            var controller = new ChatController(
                chatRepository,
                clientRepository,
                contactService.Object,
                new ServerTime(),
                restClient.Object, userManager.Object, contactAutoRating.Object);
            var result = controller.Create(chat) as ViewResult;

            Assert.AreEqual(1, chatRepository.All().Count());
            Assert.AreEqual("this is the description", chatRepository.Where(c => c.Id == chat.Id).First().Property.Single(lp => lp.Type == "Description").Value);
            Assert.AreEqual("08654321", chatRepository.Where(c => c.Id == chat.Id).First().Property.Single(lp => lp.Type == "Phone").Value);
            Assert.AreEqual("LC123456", chatRepository.Where(c => c.Id == chat.Id).First().Property.Single(lp => lp.Type == "LiveChatId").Value);
            Assert.IsFalse(chatRepository.Where(c => c.Id == chat.Id).First().Property.Any(lp => lp.Type == "Email"));
        }
        public void CreateWithInvalidModelStateNotChangeRepository()
        {
            var clientRepository  = RepositoryHelper.RepositoryLocalWithOneClient;
            var chatRepository    = new LocalRepository <Contact>();
            var client            = clientRepository.All().First();
            var contactService    = new Mock <IContactService>();
            var restClient        = new Mock <IRestClient>();
            var userManager       = new Mock <IIdentityMembershipProvider>();
            var contactAutoRating = new Mock <IContactAutoRating>();

            var chat = new ChatViewModel
            {
                ClientId    = client.Id,
                ClientName  = client.Name,
                Date        = new DateTime(2013 - 1 - 02),
                Description = "this is the description"
            };

            var controller = new ChatController(
                chatRepository,
                clientRepository,
                contactService.Object,
                new ServerTime(),
                restClient.Object, userManager.Object, contactAutoRating.Object);

            controller.ModelState.AddModelError("error", "SomeError");
            var result = controller.Create(chat) as ViewResult;

            Assert.AreEqual(0, chatRepository.All().Count());
        }
        public void CreateCanMakeClientIdsViewBag()
        {
            var clientRepository = RepositoryHelper.RepositoryLocalWithOneClient;
            var chatRepository   = new LocalRepository <Contact>();

            clientRepository.Add(new Client()
            {
                Id = 10, IsActive = false
            });
            var contactService    = new Mock <IContactService>();
            var restClient        = new Mock <IRestClient>();
            var userManager       = new Mock <IIdentityMembershipProvider>();
            var contactAutoRating = new Mock <IContactAutoRating>();


            var claim = new Claim("test", "AnyId");

            userManager.Setup(um => um.GetRoles(It.IsAny <string>())).Returns(new List <string> {
                "mockRole"
            });

            var controller = new ChatController(
                chatRepository,
                clientRepository,
                contactService.Object,
                new ServerTime(),
                restClient.Object, userManager.Object, contactAutoRating.Object);

            ModelHelper.SetClaimAsCurrentUserForController(claim, controller);
            var result = controller.Create() as ViewResult;

            var clients = result.ViewBag.ClientIds as SelectList;

            Assert.AreEqual(clientRepository.Where(cr => cr.IsActive).Count(), clients.Count());
        }