コード例 #1
0
        public void AddEnquiry_ShouldAddEnquiry()
        {
            //Arrange
            var enquiryToTest = new EnquiryViewModel()
                                {
                                    Name = "test",
                                    EmailAddress = "testEmail",
                                    CarAdsId = Guid.NewGuid()
                                };
            var expectedCarAds = new CarAds();
            _mockEnquiryService.Setup(t => t.AddEnquiry(It.IsAny<Enquiry>()));
            _mockCarAdsService.Setup(t => t.GetById(enquiryToTest.CarAdsId)).Returns(expectedCarAds);

            //Act
            var result = _controllerTotest.AddEnquiry(enquiryToTest) as ViewResult;

            //Assert
            var resultModel = result.Model as Enquiry;
            Assert.IsNotNull(resultModel);
            Assert.AreEqual(enquiryToTest.EmailAddress ,resultModel.EmailAddress);
            Assert.AreEqual(enquiryToTest.Name, resultModel.Name);
            Assert.AreEqual(expectedCarAds, resultModel.CarAds);
            _mockCarAdsService.VerifyAll();
            _mockEnquiryService.VerifyAll();
        }
コード例 #2
0
        public void Detail_ShouldReturnCollectionOfAds()
        {
            //Arrange
            var guidToTest = Guid.NewGuid();
            var expectedData = new CarAds();
            _mockCarAdsService.Setup(t => t.GetById(guidToTest)).Returns(expectedData);

            //Act
            var result = _controllerTotest.Detail(guidToTest) as ViewResult;

            //Assert
            Assert.AreEqual(expectedData, result.Model);
            _mockCarAdsService.VerifyAll();
        }
コード例 #3
0
        public void AddEnquiry_ShouldCallRepository()
        {
            //Arrange
            var enquiryToTest = new EnquiryViewModel()
            {
                Name = "test",
                EmailAddress = "testEmail",
                CarAdsId = Guid.NewGuid()
            };
            var expectedCarAds = new CarAds();
            var testGuid = Guid.NewGuid();
            _mockEnquiryService.Setup(t => t.AddEnquiry(It.IsAny<Enquiry>())).Returns(testGuid);
            _mockCarAdsService.Setup(t => t.GetById(enquiryToTest.CarAdsId)).Returns(expectedCarAds);

            //Act
            var result = _controllerTotest.Post(enquiryToTest);

            //Assert
            Assert.AreEqual(testGuid, result);
            _mockCarAdsService.VerifyAll();
            _mockEnquiryService.VerifyAll();
        }