Exemplo n.º 1
0
        public void WhenCredentialsAreNotFound_ReturnsNullAuthHeader(string username, string password)
        {
            var vendorService = new Vendor1ServiceWrapper(null, null, new Mocks.CredentialsProviderMock(username, password));
            var header        = vendorService.GetAuthorizationHeaderValue();

            Assert.Null(header.Parameter);
        }
Exemplo n.º 2
0
        public void WhenResponseIsNull_ReturnsNull()
        {
            var vendorService = new Vendor1ServiceWrapper(null, null, null);
            var response      = JsonConvert.SerializeObject(new{ total = (decimal?)null });

            Assert.Null(vendorService.ParseResponse(response));
        }
Exemplo n.º 3
0
        public void WhenResponseContainsTotal_ReturnsValue(decimal val)
        {
            var vendorService = new Vendor1ServiceWrapper(null, null, null);
            var response      = JsonConvert.SerializeObject(new{ total = val });

            Assert.Equal(val, vendorService.ParseResponse(response));
        }
Exemplo n.º 4
0
        public void WhenCredentialsAreValid_CreatesAuthheader(string username, string password)
        {
            var vendorService    = new Vendor1ServiceWrapper(null, null, new Mocks.CredentialsProviderMock(username, password));
            var header           = vendorService.GetAuthorizationHeaderValue();
            var bytes            = Encoding.ASCII.GetBytes(string.Format("{0}:{1}", username, password));
            var base64AuthString = Convert.ToBase64String(bytes);
            var testHeader       = new AuthenticationHeaderValue("Basic", base64AuthString);

            Assert.Equal(testHeader.Parameter, header.Parameter);
        }
Exemplo n.º 5
0
        public void WhenResponseIsInvalid_ReturnsNull()
        {
            var vendorService = new Vendor1ServiceWrapper(null, null, null);
            var response      = JsonConvert.SerializeObject(new { charge = 4.45m });

            // don't want the app to crash if the vendor changes the api contract
            Assert.Null(vendorService.ParseResponse(response));
            // handle unexpected response
            Assert.Null(vendorService.ParseResponse("error"));
        }
Exemplo n.º 6
0
        public void WhenResponseContainsOtherProperties_ReturnsTotal()
        {
            var vendorService = new Vendor1ServiceWrapper(null, null, null);
            var response      = JsonConvert.SerializeObject(
                new {
                total       = 4.45m,
                description = "new property"
            }
                );

            Assert.Equal(4.45m, vendorService.ParseResponse(response));
        }