Exemplo n.º 1
0
        public void Execute_WithEmptyVersion_ThrowsException()
        {
            Config.Reset();
            Config.ApiKey = WineApiTestsConstants.API_KEY;
            Config.Version = string.Empty;
            var categoryMapService = new CategoryMapService();

            try {
                CategoryMap categoryMap = categoryMapService.Show(4).Execute();
                Assert.Fail("Expected a WineApiServiceException to be thrown!");
            }
            catch (WineApiServiceException) {
            }
        }
Exemplo n.º 2
0
        public void Execute_WithNullApiKey_ThrowsException()
        {
            Config.Reset();
            Config.ApiKey = null;
            var categoryMapService = new CategoryMapService();

            try {
                CategoryMap categoryMap = categoryMapService.Show(4).Execute();
                Assert.Fail("Expected a WineApiStatusException to be thrown!");
            }
            catch (WineApiStatusException ex) {
                Assert.That(ex.Status.ReturnCode, Is.EqualTo(ReturnCode.UnableToAuthorize));
            }
        }
Exemplo n.º 3
0
        public void Execute_ShowWineTypes_Succeeds()
        {
            var categoryMapService = new CategoryMapService();

            CategoryMap categoryMap = categoryMapService.Show(4).Execute();

            Assert.That(categoryMap, Is.Not.Null);
            Assert.That(categoryMap.Status.ReturnCode, Is.EqualTo(ReturnCode.Success));
            Assert.That(categoryMap.Status.Messages, Has.Length.EqualTo(0));
            Assert.That(categoryMap.Categories, Has.Length.EqualTo(1));
            Assert.That(categoryMap.Categories[0].Id, Is.EqualTo(4));
            Assert.That(categoryMap.Categories[0].Name, Is.EqualTo("Wine Type"));
            Assert.That(categoryMap.Categories[0].Refinements, Has.Length.GreaterThan(0));
        }
Exemplo n.º 4
0
        public void Execute_BadJson_ThrowsException()
        {
            var stubUrlInvoker = MockRepository.GenerateStub<IUrlInvoker>();

            stubUrlInvoker.Stub(stub => stub.InvokeUrl(string.Empty))
                .IgnoreArguments()
                .Return(Utils.GetTestData("BadJson"));

            var categoryMapService = new CategoryMapService();
            categoryMapService.UrlInvoker = stubUrlInvoker;

            try {
                CategoryMap categoryMap = categoryMapService.Show(4).Execute();
                Assert.Fail("Expected a WineApiServiceException to be thrown!");
            }
            catch (WineApiServiceException ex) {
                Assert.That(ex.InnerException, Is.Not.Null);
            }
        }
Exemplo n.º 5
0
        public void Execute_StatusWithUnknownReturnCode_ThrowsException()
        {
            var stubUrlInvoker = MockRepository.GenerateStub<IUrlInvoker>();

            stubUrlInvoker.Stub(stub => stub.InvokeUrl(string.Empty))
                .IgnoreArguments()
                .Return(Utils.GetTestData("StatusWithUnknownReturnCode"));

            var categoryMapService = new CategoryMapService();
            categoryMapService.UrlInvoker = stubUrlInvoker;

            try {
                CategoryMap categoryMap = categoryMapService.Show(4).Execute();
                Assert.Fail("Expected a WineApiStatusException to be thrown!");
            }
            catch (WineApiStatusException ex) {
                Assert.That(ex.Status, Is.Not.Null);
                Assert.That(ex.Status.ReturnCode, Is.EqualTo((ReturnCode)123));
                Assert.That((int)ex.Status.ReturnCode, Is.EqualTo(123));
            }
        }
Exemplo n.º 6
0
        public void Execute_ShowWineTypes_Succeeds()
        {
            var stubUrlInvoker = MockRepository.GenerateStub<IUrlInvoker>();

            stubUrlInvoker.Stub(stub => stub.InvokeUrl(string.Empty))
                .IgnoreArguments()
                .Return(Utils.GetTestData("WineTypes"));

            var categoryMapService = new CategoryMapService();
            categoryMapService.UrlInvoker = stubUrlInvoker;

            CategoryMap categoryMap = categoryMapService.Show(4).Execute();

            stubUrlInvoker.AssertWasCalled(stub => stub.InvokeUrl(Arg<string>.Matches(s => s.Contains("show=(4)"))));
            Assert.That(categoryMap, Is.Not.Null);
            Assert.That(categoryMap.Status.ReturnCode, Is.EqualTo(ReturnCode.Success));
            Assert.That(categoryMap.Status.Messages, Has.Length.EqualTo(0));
            Assert.That(categoryMap.Categories, Has.Length.EqualTo(1));
            Assert.That(categoryMap.Categories[0].Id, Is.EqualTo(4));
            Assert.That(categoryMap.Categories[0].Name, Is.EqualTo("Wine Type"));
            Assert.That(categoryMap.Categories[0].Refinements, Has.Length.GreaterThan(0));
        }
Exemplo n.º 7
0
        public void Execute_StatusWithReturnCode200And2Messages_ThrowsException()
        {
            var stubUrlInvoker = MockRepository.GenerateStub<IUrlInvoker>();

            stubUrlInvoker.Stub(stub => stub.InvokeUrl(string.Empty))
                .IgnoreArguments()
                .Return(Utils.GetTestData("StatusWithReturnCode200And2Messages"));

            var categoryMapService = new CategoryMapService();
            categoryMapService.UrlInvoker = stubUrlInvoker;

            try {
                CategoryMap categoryMap = categoryMapService.Show(4).Execute();
                Assert.Fail("Expected a WineApiStatusException to be thrown!");
            }
            catch (WineApiStatusException ex) {
                Assert.That(ex.Status, Is.Not.Null);
                Assert.That(ex.Status.ReturnCode, Is.EqualTo(ReturnCode.UnableToAuthorize));
                Assert.That(ex.Status.Messages, Has.Length.EqualTo(2));
                Assert.That(ex.Status.Messages[0], Is.EqualTo("Message1"));
                Assert.That(ex.Status.Messages[1], Is.EqualTo("Message2"));
            }
        }