示例#1
0
        public void ShouldWorkNormally()
        {
            // Arrange
            var client  = A.Fake <IRestClient>();
            var options = Options.Create(new OpenFiscaOptions()
            {
                Url = "http://localhost:5000"
            });

            var response = new OpenFiscaResource();

            response.CreatePerson("test_person");
            response.SetProp("test_person", "test_key", 6);

            var postResult = A.Fake <RestResponse <OpenFiscaResource> >();

            postResult.Data       = response;
            postResult.StatusCode = System.Net.HttpStatusCode.OK;

            A.CallTo(() => client.Execute <OpenFiscaResource>(A <RestRequest> ._, Method.POST))
            .Returns(postResult);

            // Act
            var sut    = new OpenFiscaLib(client, options);
            var req    = new OpenFiscaResource();
            var result = sut.Calculate(req);

            // Assert
            Assert.Equal(6, result.GetProp("test_person", "test_key"));
        }
示例#2
0
        public void ShouldWorkNormally()
        {
            // Arrange
            string  personKey = "personKey";
            string  propKey   = "propKey";
            decimal value     = 983.333m;

            var restClient = A.Fake <RestClient>();

            var openFiscaResponse = new OpenFiscaResource();

            openFiscaResponse.CreatePerson(personKey);
            openFiscaResponse.SetProp(personKey, propKey, value);

            var restResponse = new RestResponse <OpenFiscaResource> {
                Data       = openFiscaResponse,
                StatusCode = System.Net.HttpStatusCode.OK
            };

            A.CallTo(() => restClient.Execute <OpenFiscaResource>(A <RestRequest> ._, Method.POST))
            .Returns(restResponse);

            var options = Options.Create(new OpenFiscaOptions()
            {
                Url = "localhost:5000"
            });

            // Act
            var sut     = new OpenFiscaLib(restClient, options);
            var request = A.Fake <OpenFiscaResource>();
            var result  = sut.Calculate(request);

            // Assert
            Assert.Equal(value, result.GetProp(personKey, propKey));
        }
示例#3
0
        public void ShouldThrowOnMissingVariable()
        {
            // Arrange
            var restClient = A.Fake <RestClient>();

            var errorResponse = new RestResponse <OpenFiscaResource>()
            {
                StatusCode = System.Net.HttpStatusCode.NotFound
            };

            A.CallTo(() => restClient.Execute <OpenFiscaResource>(A <RestRequest> ._, Method.POST))
            .Returns(errorResponse);

            var options = Options.Create(new OpenFiscaOptions()
            {
                Url = "localhost:5000"
            });

            // Act
            var sut     = new OpenFiscaLib(restClient, options);
            var request = A.Fake <OpenFiscaResource>();

            Assert.Throws <OpenFiscaException>(() => sut.Calculate(request));
        }