public void GetAccount_GetAccountsbyAccountId_Succeed()
        {
            AccountsController controller = new AccountsController(mockAccountService.Object, mockWebAnalyticsProviderService.Object);

            this.SetupControllerTests(controller, "http://localhost/STCRMService/api/accounts/1", HttpMethod.Get);

            GetAccountResponse response = mockRepository.Create <GetAccountResponse>().Object;

            response.AccountViewModel = MockData.CreateMockList <AccountViewModel>(mockRepository).Select(c => c.Object).FirstOrDefault();

            mockAccountService.Setup(c => c.GetAccount(It.IsAny <GetAccountRequest>())).Returns(response);

            var httpResponseMessage = controller.GetAccountById(SAMPLE_ACCOUNT_ID);
            var accountResponse     = httpResponseMessage.Content.ReadAsAsync <GetAccountResponse>().ContinueWith(
                t => { return(t.Result); }).Result;

            mockRepository.VerifyAll();
            Assert.AreEqual(httpResponseMessage.StatusCode, HttpStatusCode.OK);
            Assert.AreEqual(accountResponse.Exception, null);
        }
Exemplo n.º 2
0
        public void GetTour_GetTourforContact_ReturnSuccess()
        {
            ToursController controller = new ToursController(mockTourService.Object);

            this.SetupControllerTests(controller, "http://localhost/STCRMService/api/tour/1", HttpMethod.Get);

            var mockResponse = mockRepository.Create <GetTourResponse>();

            GetTourResponse response = mockRepository.Create <GetTourResponse>().Object;

            response.TourViewModel = MockData.CreateMockList <TourViewModel>(mockRepository).Select(c => c.Object).FirstOrDefault();
            mockTourService.Setup(c => c.GetTour(It.IsAny <int>())).Returns(response);
            var httpResponseMessage = controller.GetTour(SAMPLE_TOUR_ID);
            var contactResponse     = httpResponseMessage.Content.ReadAsAsync <GetTourResponse>().ContinueWith(
                t => { return(t.Result); }).Result;

            mockRepository.VerifyAll();
            Assert.AreEqual(httpResponseMessage.StatusCode, HttpStatusCode.OK);
            Assert.AreEqual(contactResponse.Exception, null);
        }
Exemplo n.º 3
0
        public void Notes_GetAllNotesforContacts_ValidNote()
        {
            NoteController controller = new NoteController(mockNoteService.Object);

            this.SetupControllerTests(controller, "http://localhost/STCRMService/api/notes", HttpMethod.Get);

            var mockResponse = mockRepository.Create <GetNotesListRequest>();

            GetNotesListResponse response = mockRepository.Create <GetNotesListResponse>().Object;

            response.NotesListViewModel = MockData.CreateMockList <NoteViewModel>(mockRepository).Select(c => c.Object).ToList();
            mockNoteService.Setup(c => c.GetNotesContacts(It.IsAny <GetNotesListRequest>())).Returns(response);
            var httpResponseMessage = controller.GetContactNotes(SAMPLE_CONTACT_ID);
            var contactResponse     = httpResponseMessage.Content.ReadAsAsync <GetNotesListResponse>().ContinueWith(
                t => { return(t.Result); }).Result;

            mockRepository.VerifyAll();
            Assert.AreEqual(10, contactResponse.NotesListViewModel.Count());
            Assert.AreEqual(httpResponseMessage.StatusCode, HttpStatusCode.OK);
            Assert.AreEqual(contactResponse.Exception, null);
        }
        public void GetAccount_GetAccountsbyAccountNameRuntimeError_500InternalServerError()
        {
            AccountsController controller = new AccountsController(mockAccountService.Object, mockWebAnalyticsProviderService.Object);

            this.SetupControllerTests(controller, "http://localhost/STCRMService/api/accounts/account1", HttpMethod.Get);

            var mockResponse            = mockRepository.Create <GetAccountResponse>();
            GetAccountResponse response = mockRepository.Create <GetAccountResponse>().Object;

            response.AccountViewModel = MockData.CreateMockList <AccountViewModel>(mockRepository).Select(c => c.Object).FirstOrDefault();
            mockAccountService.Setup(cs => cs.GetAccountByName(It.IsAny <GetAccountNameRequest>())).Returns(mockResponse.Object);
            mockResponse.Setup(r => r.Exception).Returns(new InvalidOperationException());

            var httpResponseMessage = controller.GetAccountByName(SAMPLE_ACCOUNT_NAME);
            var accountResponse     = httpResponseMessage.Content.ReadAsAsync <GetAccountResponse>().ContinueWith(
                t => { return(t.Result); }).Result;
            var exception = accountResponse.Exception;

            mockRepository.VerifyAll();
            Assert.AreEqual(httpResponseMessage.StatusCode, HttpStatusCode.InternalServerError);
            Assert.AreNotEqual(exception, null);
        }
Exemplo n.º 5
0
        public void GetNote_GetNoteforContact_RuntimeError_500InternalServerError()
        {
            NoteController controller = new NoteController(mockNoteService.Object);

            this.SetupControllerTests(controller, "http://localhost/STCRMService/api/note/1", HttpMethod.Get);
            var mockResponse = mockRepository.Create <GetNoteResponse>();

            GetNoteResponse responce = mockRepository.Create <GetNoteResponse>().Object;

            responce.NoteViewModel = MockData.CreateMockList <NoteViewModel>(mockRepository).Select(c => c.Object).FirstOrDefault();
            mockNoteService.Setup(c => c.GetNote(It.IsAny <GetNoteRequest>())).Returns(mockResponse.Object);
            mockResponse.Setup(r => r.Exception).Returns(new InvalidOperationException());

            var httpResponseMessage = controller.GetNote(SAMPLE_NOTE_ID);
            var postResponse        = httpResponseMessage.Content.ReadAsAsync <GetNoteResponse>().ContinueWith(
                t => { return(t.Result); }).Result;

            mockRepository.VerifyAll();

            Assert.AreEqual(httpResponseMessage.StatusCode, HttpStatusCode.InternalServerError);
            Assert.AreNotEqual(postResponse.Exception, null);
        }