Exemple #1
0
        public async Task TranslateRelativeUrl()
        {
            var httpSenderMock = new HttpSenderMock();
            var sender         = new ValueTranslatorHttpSender(httpSenderMock, "producer");
            await sender.SendRequestAsync(HttpMethod.Get, $"Foos/{_decoratedConsumerId}");

            Assert.AreEqual($"Foos/{ProducerId}", httpSenderMock.RelativeUrl);
        }
Exemple #2
0
        public async Task TranslateUserId()
        {
            FulcrumApplication.Context.ValueProvider.SetValue("DecoratedUserId", _decoratedConsumerId);

            var httpSenderMock = new HttpSenderMock();
            var sender         = new ValueTranslatorHttpSender(httpSenderMock, "producer");
            await sender.SendRequestAsync(HttpMethod.Get, $"Foos/{_decoratedConsumerId}");

            Assert.AreEqual(ProducerId, sender.TranslatedUserId_OnlyForUnitTests);
        }
Exemple #3
0
        public async Task DoNotTranslateBody()
        {
            var httpSenderMock = new HttpSenderMock();
            var sender         = new ValueTranslatorHttpSender(httpSenderMock, "producer");
            var inBody         = new Foo {
                Id = _decoratedConsumerId, Name = "name"
            };
            await sender.SendRequestAsync(HttpMethod.Get, $"Foos/{ProducerId}", inBody);

            Assert.IsNotNull(httpSenderMock.ReceivedBody);
            var outBody = httpSenderMock.ReceivedBody as Foo;

            Assert.IsNotNull(outBody);
            Assert.AreEqual(ProducerId, outBody.Id);
            Assert.AreEqual(inBody.Name, outBody.Name);
        }
Exemple #4
0
        public async Task TranslatorServiceIsNotCalledForIfNoTranslations()
        {
            _translatorServiceMock = new Mock <ITranslatorService>();
            _translatorServiceMock
            .Setup(ts => ts.TranslateAsync(
                       It.IsAny <IEnumerable <string> >(),
                       It.IsAny <string>(),
                       It.IsAny <CancellationToken>()))
            .ThrowsAsync(new Exception("ITranslatorService should not be called if no translations"));
            ValueTranslatorHttpSender.TranslatorService = _translatorServiceMock.Object;

            var sender = new ValueTranslatorHttpSender(new HttpSenderMock(), "producer");
            var inBody = new Tenant("o", "e");
            // There are no translations in this request, so ITranslatorService.TranslateAsync should not be called
            await sender.SendRequestAsync(HttpMethod.Get, $"Tenants/{ProducerId}", inBody);
        }
Exemple #5
0
        public async Task TranslatePageContent()
        {
            var httpSenderMock = new HttpSenderMock();
            var sender         = new ValueTranslatorHttpSender(httpSenderMock, "producer");
            var inBody         = new Foo {
                Id = _decoratedConsumerId, Name = "name"
            };
            var result = await sender.SendRequestAsync <PageEnvelope <Foo>, Foo>(HttpMethod.Get, $"Foos/{ProducerId}", inBody);

            Assert.IsNotNull(result?.Body);
            Assert.IsNotNull(result.Body.Data);
            Assert.IsTrue(result.Body.Data.Count() > 0);
            foreach (var foo in result.Body.Data)
            {
                VerifyFoo(foo);
            }
        }
Exemple #6
0
        public async Task TranslateListBody()
        {
            var httpSenderMock = new HttpSenderMock();
            var sender         = new ValueTranslatorHttpSender(httpSenderMock, "producer");
            var sentBody       = new Foo {
                Id = _decoratedConsumerId, Name = "name"
            };
            var result = await sender.SendRequestAsync <IEnumerable <Foo>, Foo>(HttpMethod.Get, $"Foos", sentBody);

            var resultBody = result.Body;

            Assert.IsNotNull(resultBody);
            var foo = resultBody.FirstOrDefault();

            Assert.IsNotNull(foo);
            VerifyFoo(foo);
        }
Exemple #7
0
        public async Task TranslateObjectBody()
        {
            var httpSenderMock = new HttpSenderMock();
            var sender         = new ValueTranslatorHttpSender(httpSenderMock, "producer");
            var sentBody       = new Foo {
                Id = _decoratedConsumerId, Name = "name"
            };
            var result = await sender.SendRequestAsync <Foo, Foo>(HttpMethod.Get, $"Foos/{ProducerId}", sentBody);

            Assert.IsNotNull(httpSenderMock.ReceivedBody);
            var receivedBody = httpSenderMock.ReceivedBody as Foo;

            Assert.IsNotNull(receivedBody);
            Assert.AreEqual(ProducerId, receivedBody.Id);
            Assert.AreEqual(sentBody.Name, receivedBody.Name);
            Assert.IsNotNull(result.Body);
            var resultBody = result.Body;

            Assert.IsNotNull(resultBody);
            VerifyFoo(resultBody);
        }