Exemple #1
0
        public void AccountCancellation_Given_ValidModel_Should_SendPOSTRequest()
        {
            //Arrange
            var mockingKernel = new MoqMockingKernel();
            var mockConfig    = mockingKernel.GetMock <IConfig>();

            mockConfig.SetupGet(p => p.SimfyBaseUrl).Returns("SimfyBaseUrl");
            mockConfig.SetupGet(p => p.SimfyApiUsername).Returns("SimfyApiUsername");
            mockConfig.SetupGet(p => p.SimfyApiPassword).Returns("SimfyApiPassword");
            mockConfig.SetupGet(p => p.SimfyEmail).Returns("SimfyEmail");
            var                 mockHttpUtility  = mockingKernel.GetMock <IHttpUtility>();
            var                 service          = new ThirdPartyServiceSimfy(mockingKernel);
            PrivateObject       privateObject    = new PrivateObject(service);
            var                 SimfyBaseUrl     = privateObject.GetFieldOrProperty("SimfyBaseUrl", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var                 SimfyApiUsername = privateObject.GetFieldOrProperty("SimfyApiUsername", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var                 SimfyApiPassword = privateObject.GetFieldOrProperty("SimfyApiPassword", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var                 SimfyEmail       = privateObject.GetFieldOrProperty("SimfyEmail", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var                 simfy            = SimfyBaseUrl.ToString() + "/unsubscribe";;
            HttpResponseMessage value            = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
            var                 accountResponse  = new SimfyAccountCancellationRequest();

            value.Content = new StringContent(JsonConvert.SerializeObject(accountResponse));
            value.Content.Headers.Clear();
            value.Content.Headers.Add("Content-Type", "application/json");
            mockHttpUtility.Setup(p => p.PostRequest(simfy, "", accountResponse, null, false, 5))
            .Returns(value);
            //Act

            service.AccountCancellation(accountResponse);
            //Assert
            Assert.AreEqual(accountResponse.ApiLogin, SimfyApiUsername);
            Assert.AreEqual(accountResponse.ApiPassword, SimfyApiPassword);
            mockHttpUtility.Verify(p => p.PostRequest(simfy, "", accountResponse, null, false, 5), Times.Once);
        }
Exemple #2
0
        public void AccountCancellation_Given_ModelFailure_Should_ReturnFailureModel()
        {
            //Arrange
            var mockingKernel = new MoqMockingKernel();
            var mockConfig    = mockingKernel.GetMock <IConfig>();

            mockConfig.SetupGet(p => p.SimfyBaseUrl).Returns("SimfyBaseUrl");
            mockConfig.SetupGet(p => p.SimfyApiUsername).Returns("SimfyApiUsername");
            mockConfig.SetupGet(p => p.SimfyApiPassword).Returns("SimfyApiPassword");
            mockConfig.SetupGet(p => p.SimfyEmail).Returns("SimfyEmail");
            var                 mockHttpUtility  = mockingKernel.GetMock <IHttpUtility>();
            var                 service          = new ThirdPartyServiceSimfy(mockingKernel);
            PrivateObject       privateObject    = new PrivateObject(service);
            var                 SimfyBaseUrl     = privateObject.GetFieldOrProperty("SimfyBaseUrl", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var                 SimfyApiUsername = privateObject.GetFieldOrProperty("SimfyApiUsername", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var                 SimfyApiPassword = privateObject.GetFieldOrProperty("SimfyApiPassword", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var                 SimfyEmail       = privateObject.GetFieldOrProperty("SimfyEmail", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var                 simfy            = SimfyBaseUrl.ToString() + "/unsubscribe";;
            HttpResponseMessage value            = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
            var                 accountResponse  = new SimfyAccountCancellationResponse()
            {
                Success        = false,
                FailureReasons = new[]
                {
                    "Test Failed To Cancel Simfy Service"
                }
            };

            value.Content = new StringContent(JsonConvert.SerializeObject(accountResponse));
            var model = new SimfyAccountCancellationRequest();

            value.Content.Headers.Clear();
            value.Content.Headers.Add("Content-Type", "application/json");
            mockHttpUtility.Setup(p => p.PostRequest(simfy, "", model, null, false, 5))
            .Returns(value);
            //Act

            var responce = service.AccountCancellation(model);

            //Assert
            mockHttpUtility.Verify(p => p.PostRequest(simfy, "", model, null, false, 5), Times.Once);

            Assert.IsFalse(responce.IsSuccess);
            Assert.IsTrue(!string.IsNullOrEmpty(responce.Message));
        }
Exemple #3
0
        public void AccountCancellation_Given_HTTPRequestException_Should_CatchException()
        {
            //Arrange
            var mockingKernel = new MoqMockingKernel();
            var mockConfig    = mockingKernel.GetMock <IConfig>();

            mockConfig.SetupGet(p => p.SimfyBaseUrl).Returns("SimfyBaseUrl");
            mockConfig.SetupGet(p => p.SimfyApiUsername).Returns("SimfyApiUsername");
            mockConfig.SetupGet(p => p.SimfyApiPassword).Returns("SimfyApiPassword");
            mockConfig.SetupGet(p => p.SimfyEmail).Returns("SimfyEmail");
            var                             mockHttpUtility  = mockingKernel.GetMock <IHttpUtility>();
            var                             service          = new ThirdPartyServiceSimfy(mockingKernel);
            PrivateObject                   privateObject    = new PrivateObject(service);
            var                             SimfyBaseUrl     = privateObject.GetFieldOrProperty("SimfyBaseUrl", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var                             SimfyApiUsername = privateObject.GetFieldOrProperty("SimfyApiUsername", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var                             SimfyApiPassword = privateObject.GetFieldOrProperty("SimfyApiPassword", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var                             SimfyEmail       = privateObject.GetFieldOrProperty("SimfyEmail", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var                             simfy            = SimfyBaseUrl.ToString() + "/unsubscribe";;
            HttpResponseMessage             value            = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError);
            SimfyAccountCancellationRequest accountResponse  = new SimfyAccountCancellationRequest()
            {
            };

            value.Content = new StringContent(JsonConvert.SerializeObject(accountResponse))
            {
            };
            value.Content.Headers.Clear();
            value.Content.Headers.Add("Content-Type", "application/json");
            mockHttpUtility.Setup(p => p.PostRequest(simfy, "", accountResponse, null, false, 5))
            .Throws <Exception>();
            //Act

            var responce = service.AccountCancellation(accountResponse);

            //Assert
            mockHttpUtility.Verify(p => p.PostRequest(simfy, "", accountResponse, null, false, 5), Times.Once);
            Assert.IsFalse(responce.IsSuccess);
            Assert.AreEqual("Exception: Cancelling Simfy Account.", responce.Message);
        }