예제 #1
0
        public async Task ShouldReturnNullIfMissing()
        {
            var id         = 8;
            var clientMock = new ClientMock(_pact)
            {
                ConditionDescription = $"No subject with id '{id}' exists",
                Response             = new ProviderServiceResponse {
                    Status = 404
                }
            };
            var repo    = new PactConsumer1.ProducerRepository(clientMock);
            var product = await repo.GetProductById(id);

            Assert.Null(product);
        }
예제 #2
0
        public async Task ShouldReturnProductIfExists()
        {
            var id         = 1;
            var clientMock = new ClientMock(_pact)
            {
                ConditionDescription = $"Subject with id '{id}' exists",
                Response             = new ProviderServiceResponse {
                    Status  = 200,
                    Headers = new Dictionary <string, string> {
                        { "Content-Type", "application/json; charset=utf-8" }
                    },
                    Body = new ProductDto {
                        Id   = id,
                        Time = new DateTime(1984, 01, 01),
                        Type = "TypEtt"
                    }
                }
            };
            var repo    = new PactConsumer1.ProducerRepository(clientMock);
            var product = await repo.GetProductById(id);

            Assert.NotNull(product);
            Assert.Equal(id, product.Id);
        }
예제 #3
0
        public async Task ShouldReturnObjectIfCreateSucceeds()
        {
            var type       = "TypTvå";
            var clientMock = new ClientMock(_pact)
            {
                ConditionDescription = $"Creating new product",
                Response             = new ProviderServiceResponse {
                    Status  = 201,
                    Headers = new Dictionary <string, string> {
                        { "Content-Type", "application/json; charset=utf-8" }
                    },
                    Body = new ProductDto {
                        Id   = 10,
                        Time = new DateTime(1984, 01, 01),
                        Type = type
                    }
                }
            };
            var repo    = new PactConsumer1.ProducerRepository(clientMock);
            var product = await repo.CreateProductOfType(type);

            Assert.NotNull(product);
            Assert.Equal(type, product.Type);
        }