Exemplo n.º 1
0
        public async void GetPlansAsync_Returns_Single_Plan()
        {
            int count         = 0;
            var mockTransport = new TransportMock();

            mockTransport.When(x => x.GetJsonResult(It.IsAny <string>()))
            .Return(() =>
            {
                var tcs = new TaskCompletionSource <string>();
                tcs.SetResult(count == 0 ? singleServiceTypeJson : singlePlanJson);
                count++;
                return(tcs.Task);
            });

            var mockClassFactory = new ClassFactoryMock();

            mockClassFactory.When(x => x.CreateTransport())
            .Return(mockTransport);

            ClassFactory.Instance = mockClassFactory;

            var services = new Services();
            var plans    = await services.GetPlansAsync("Central Gathering", 4);

            Assert.True(plans.Count == 1);
        }
Exemplo n.º 2
0
        public async void GetPlansAsync_Returns_Empty_List_If_Json_Null()
        {
            var mockTransport = new TransportMock();

            mockTransport.When(x => x.GetJsonResult(It.IsAny <string>()))
            .Return(() =>
            {
                var tcs = new TaskCompletionSource <string>();
                tcs.SetResult(null);
                return(tcs.Task);
            });

            var mockClassFactory = new ClassFactoryMock();

            mockClassFactory.When(x => x.CreateTransport())
            .Return(mockTransport);

            ClassFactory.Instance = mockClassFactory;

            var services = new Services();
            var plans    = await services.GetPlansAsync("Central Gathering", 4);

            Assert.True(plans.Count == 0);
        }