コード例 #1
0
        public async Task User_can_get_solar_times_for_a_specific_location_and_date()
        {
            // Arrange
            using var app = new FakeApp();

            var date            = new DateTimeOffset(2020, 07, 03, 0, 0, 0, TimeSpan.FromHours(+3));
            var expectedSunrise = new DateTimeOffset(2020, 07, 03, 04, 52, 23, TimeSpan.FromHours(+3));
            var expectedSunset  = new DateTimeOffset(2020, 07, 03, 21, 11, 45, TimeSpan.FromHours(+3));

            // Act
            var query = new QueryBuilder
            {
                { "lat", "50.45" },
                { "lon", "30.52" },
                { "date", date.ToString("O", CultureInfo.InvariantCulture) }
            };

            var response = await app.Client.GetStringAsync($"/solartimes/by_location{query}");

            var solarTimes = JsonSerializer.Deserialize <SolarTimes>(response, _serializerOptions);

            // Assert
            solarTimes.Sunrise.Should().BeCloseTo(expectedSunrise, TimeSpan.FromSeconds(1));
            solarTimes.Sunset.Should().BeCloseTo(expectedSunset, TimeSpan.FromSeconds(1));
        }
コード例 #2
0
        public async Task User_can_get_solar_times_for_their_location_by_ip()
        {
            // Arrange
            using var app = new FakeApp
                  {
                      ClientIp = IPAddress.Parse("20.112.101.1")
                  };

            var date            = new DateTimeOffset(2020, 07, 03, 0, 0, 0, TimeSpan.FromHours(-5));
            var expectedSunrise = new DateTimeOffset(2020, 07, 03, 05, 20, 37, TimeSpan.FromHours(-5));
            var expectedSunset  = new DateTimeOffset(2020, 07, 03, 20, 28, 54, TimeSpan.FromHours(-5));

            // Act
            var query = new QueryBuilder
            {
                { "date", date.ToString("O", CultureInfo.InvariantCulture) }
            };

            var response = await app.Client.GetStringAsync($"/solartimes/by_ip{query}");

            var solarTimes = JsonSerializer.Deserialize <SolarTimes>(response, _serializerOptions);

            // Assert
            solarTimes.Sunrise.Should().BeCloseTo(expectedSunrise, TimeSpan.FromSeconds(1));
            solarTimes.Sunset.Should().BeCloseTo(expectedSunset, TimeSpan.FromSeconds(1));
        }
コード例 #3
0
 public ConnectionTestsBase()
 {
     App               = new FakeApp();
     Socket            = new FakeSocket();
     Connection        = new Connection(new FakeServices(), App.Call, Socket, OnDisconnected);
     DisconnectedEvent = new ManualResetEvent(false);
 }
コード例 #4
0
        void InitApp(string resultStatus)
        {
            _app = new FakeApp().ForSynchronousResult(
                resultStatus,
                new Dictionary <string, string> (),
                null
                );

            _handler = new Handler(_app.Call);
        }
コード例 #5
0
 public FrameTestsBase()
 {
     Services = new FakeServices();
     App      = new FakeApp();
     Output   = new FakeOutput();
     Input    = new FakeInput();
     Frame    = new Frame(
         new FrameContext
     {
         Services = Services,
         App      = App.Call,
         Write    = Output.Write,
         Flush    = Output.Flush,
         End      = Output.End,
     });
     Input.Consume = (baton, callback) => Frame.Consume(baton, (frame, ex) => callback(ex));
 }
コード例 #6
0
        public async Task User_can_get_solar_times_for_their_location_by_ip_multiple_times_with_the_same_result()
        {
            // Arrange
            using var app = new FakeApp();

            // Act
            var collectedSolarTimes = new List <SolarTimes>();

            for (var i = 0; i < 3; i++)
            {
                var response = await app.Client.GetStringAsync("/solartimes/by_ip");

                var solarTimes = JsonSerializer.Deserialize <SolarTimes>(response, _serializerOptions);

                collectedSolarTimes.Add(solarTimes);
            }

            // Assert
            collectedSolarTimes.Select(t => t.Sunrise).Distinct().Should().ContainSingle();
            collectedSolarTimes.Select(t => t.Sunset).Distinct().Should().ContainSingle();
        }
コード例 #7
0
        public void WhenAPOSTReqIsProvided_ServiceShouldReturnCorrectResp()
        {
            var fakeResponse       = new FakeGetResponse("I am fake");
            var fakeMessageHandler = new FakeHttpMessageHandler(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(JsonConvert.SerializeObject(fakeResponse),
                                               Encoding.UTF8,
                                               "application/json")
            });
            var fakeClient = new HttpClient(fakeMessageHandler);

            var mockClientFactory = Substitute.For <IHttpClientFactory>();

            mockClientFactory.CreateClient().Returns(fakeClient);

            var app = new FakeApp(mockClientFactory);

            //Act
            FakeGetResponse resp = app
                                   .GetRequest <FakeGetRequest, FakeGetResponse>(new FakeGetRequest()).Result;

            Assert.True(resp.body == "I am fake");
        }
コード例 #8
0
 public DADO_app()
 {
     this.app = new FakeApp();
     this.sut = new InventarioApp(app);
 }
コード例 #9
0
 public void CloseFakeApp(FakeApp fa)
 {
     desktopAnimator.SetPivot(fa.GetEntrancePivot());
     desktopAnimator.ZoomIn();
     fa.Exit();
 }
コード例 #10
0
 public void OpenFakeApp(FakeApp fa)
 {
     desktopAnimator.SetPivot(fa.GetEntrancePivot());
     desktopAnimator.ZoomOut();
     fa.Enter();
 }