private void MockGetThisUserHttpRequest(int userId)
 {
     MockHttp.Expect(HttpMethod.Get, "http://localhost/User/GetUser/-1")
     .RespondValues(new UserObject {
         Id = userId
     });
 }
    public async Task StubIntegration_Proxy_Post_ProxiesCorrectly()
    {
        // Arrange
        var          url         = $"{TestServer.BaseAddress}todoitems/todos";
        const string postContent = "this is the content";
        var          request     = new HttpRequestMessage
        {
            RequestUri = new Uri(url),
            Method     = HttpMethod.Post,
            Content    = new StringContent(postContent, Encoding.UTF8, Constants.TextMime)
        };

        MockHttp
        .When(HttpMethod.Post, "https://jsonplaceholder.typicode.com/todos")
        .WithContent(postContent)
        .Respond(Constants.TextMime, "OK from Proxy");

        // Act / Assert
        using var response = await Client.SendAsync(request);

        var content = await response.Content.ReadAsStringAsync();

        Assert.AreEqual("OK from Proxy", content);
        Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
    }
 private void InitializeHttpCallUpdateItem(int databaseThisUserId, int applicationUserId)
 {
     MockHttp.Expect(HttpMethod.Get, "http://localhost/StarpointsManager/GetItem/-1/107")
     .RespondValues(new StarpointsItem
     {
         Id = 107,
         ApplicationUserId = applicationUserId
     });
     MockHttp.Expect(HttpMethod.Get, $"http://localhost/User/GetUser/-1")
     .RespondValues(new UserObject {
         Id = databaseThisUserId
     });
     if (databaseThisUserId != applicationUserId)
     {
         MockHttp.Expect(HttpMethod.Get, $"http://localhost/User/GetUser/{applicationUserId}")
         .RespondValues(new UserObject {
             Id = applicationUserId
         });
     }
     MockHttp.Expect(HttpMethod.Get, "http://localhost/StarpointsManager/GetStarpointsType/-1")
     .RespondValues(new[] { new StarpointsType {
                                Id = 1
                            } });
     if (databaseThisUserId != applicationUserId)
     {
         MockHttp.Expect(HttpMethod.Get, $"http://localhost/User/GetUserStartechs/{applicationUserId}")
         .RespondValues(new[] { Startechs.Dotnet });
     }
 }
示例#4
0
        public async Task Should_RequestWithHeaderAndParams_When_ConfigureServeralOptions()
        {
            // Given
            var content = new { A = "b" };
            var request = MockHttp.When(HttpMethod.Post, "http://localhost:8080/api/index")
                          .WithHeaders(HttpRequestHeader.Authorization.ToString(), "Bearer AccessToken")
                          .WithQueryString("a", "b")
                          .WithQueryString("c", "d")
                          .WithContent(JsonConvert.SerializeObject(content))
                          .Respond(HttpStatusCode.OK, new StringContent("Hello"));

            // When
            var message = await Client.WithUri("http://localhost:8080/api/index")
                          .WithHeader(HttpRequestHeader.Authorization, "Bearer AccessToken")
                          .WithQuery("a", "b")
                          .WithQuery("c", "d")
                          .WithJsonContent(content)
                          .PostAsync();

            // Then
            message.StatusCode.Should().Be(HttpStatusCode.OK);
            var response = await message.Content.ReadAsStringAsync();

            response.Should().Be("Hello");
            MockHttp.GetMatchCount(request).Should().Be(1);
        }
示例#5
0
        public async Task should_load_the_leaders_from_the_right_startechType_api()
        {
            MockHttp.Expect(HttpMethod.Get, "http://localhost/AdminLeader/Admin/GetLeaders").RespondValues(new UserObject[0]);
            var target = CreateComponent(StartechType, DisplayName);
            await Task.Delay(30);

            MockHttp.VerifyNoOutstandingExpectation();
        }
        private Services.TokenProvider CreateTokenProvider()
        {
            var http    = MockHttp.ToHttpClient();
            var options = new ApigeeClientOptions(Email, Password, OrgName, EnvName, BaseUrl, AuthUrl,
                                                  TimeSpan.FromSeconds(RequestTimeOut), EntitiesLimit);
            var httpService = new HttpService(http);

            return(new Services.TokenProvider(options, httpService));
        }
        public async Task for_updated_item_created_by_this_user_the_item_should_be_load_from_server()
        {
            InitializeHttpCallUpdateItem(11, 11);
            var target = CreateComponent(TestItemId);
            await Task.Delay(30);

            target.Instance.Item.Id.Should().Be(107);
            MockHttp.VerifyNoOutstandingExpectation();
        }
示例#8
0
        public async Task when_the_points_to_validate_is_load_isLoad_should_be_true()
        {
            MockHttp.Expect(HttpMethod.Get, "http://localhost/StarpointsManager/GetInValidationStarpoints")
            .RespondValues(new[] { new StarpointsItem() });
            var target = CreateComponent();
            await Task.Delay(50);

            target.Instance.IsLoad.Should().BeTrue();
        }
        public async Task for_updated_item_created_for_another_user_available_startech_should_be_retrieved_from_server()
        {
            InitializeHttpCallUpdateItem(15, 17);
            var target = CreateComponent(TestItemId);
            await Task.Delay(30);

            target.Instance.AvailableStartechs.Should().BeEquivalentTo(Startechs.Dotnet);
            MockHttp.VerifyNoOutstandingExpectation();
        }
示例#10
0
        public async Task when_loading_leaders_the_razor_component_should_be_refreshed_with_leader()
        {
            MockHttp.Expect(HttpMethod.Get, "http://localhost/AdminLeader/Admin/GetLeaders")
            .RespondValues(new [] { new UserObject {
                                        UserName = "******"
                                    } });
            var target = CreateComponent(StartechType, DisplayName);

            target.WaitForAssertion(() => target.Nodes.QuerySelectorAll("li:contains(\"jsqdklqdqs\")").Any(), TimeSpan.FromMilliseconds(30));
        }
示例#11
0
        public async Task when_removing_a_leader_the_right_startechtype_api_should_be_called()
        {
            MockHttp.Expect(HttpMethod.Get, "http://localhost/AdminLeader/Admin/GetLeaders").RespondValues(Users);
            var target = CreateComponent(StartechType, DisplayName);
            await Task.Delay(30);

            MockHttp.Expect(HttpMethod.Get, "http://localhost/AdminLeader/Admin/RemoveLeader/1").Respond(HttpStatusCode.OK);
            target.Instance.OnRemove(Users.First());
            MockHttp.VerifyNoOutstandingExpectation();
        }
示例#12
0
        public async Task when_removing_a_leader_the_leader_list_should_be_called()
        {
            MockHttp.Expect(HttpMethod.Get, "http://localhost/AdminLeader/Admin/GetLeaders").RespondValues(Users);
            var target = CreateComponent(StartechType, DisplayName);
            await Task.Delay(30);

            MockHttp.Expect(HttpMethod.Get, "http://localhost/AdminLeader/Admin/RemoveLeader/1").Respond(HttpStatusCode.OK);
            MockHttp.Expect(HttpMethod.Get, "http://localhost/AdminLeader/Admin/GetLeaders").RespondValues(new UserObject[0]);
            target.Instance.OnRemove(Users.First());
            target.WaitForAssertion(() => target.Nodes.QuerySelectorAll("li:contains(\"Admin\")").Empty(), TimeSpan.FromMilliseconds(30));
        }
示例#13
0
        public async Task should_load_startech_members_from_right_startech()
        {
            MockHttp.Expect(HttpMethod.Get, "http://localhost/AdminMember/Dotnet/GetMembers")
            .RespondValues(new[] { new UserObject {
                                       Id = 12, UserName = "******"
                                   } });
            var target = CreateComponent(StartechType);
            await Task.Delay(30);

            MockHttp.VerifyNoOutstandingExpectation();
        }
示例#14
0
        public void Arrange()
        {
            Setup();

            var certificateResponses = Builder <CertificateResponse> .CreateListOfSize(10).Build();

            MockHttp.When("http://localhost:59022/api/v1/certificates/tobeprinted")
            .Respond("application/json", JsonConvert.SerializeObject(certificateResponses));     // Respond with JSON

            _result = AssessorServiceApi.GetCertificatesToBePrinted().Result;
        }
示例#15
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        public async Task should_load_startech_members_at_initialization()
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            MockHttp.Expect(HttpMethod.Get, "http://localhost/AdminMember/Dotnet/GetMembers")
            .RespondValues(new[] { new UserObject {
                                       Id = 12, UserName = "******"
                                   } });
            var target = CreateComponent(StartechType);

            target.WaitForAssertion(() => target.Nodes.Any(x => x.NodeValue?.Contains("dotnet_Member") ?? false));
        }
        public async Task when_creating_an_item_with_this_user_createItem_service_should_navigate_to_this_users_points()
        {
            InitializeHttpCallNewItem(ThisUserId);
            var target = CreateComponent(ThisUserId);
            await Task.Delay(30);

            MockHttp.Expect(HttpMethod.Post, "http://localhost/StarpointsManager/CreateStarpoints/-1").Respond(HttpStatusCode.OK);
            MockGetThisUserHttpRequest(ThisUserDatabaseId);
            await target.Instance.UpdateOrCreate();

            HasNavigatedToUrl.Should().Be("/Points/-1");
        }
        public async Task when_creating_an_item_with_this_user_createItem_service_should_be_called_with_this_user_id()
        {
            InitializeHttpCallNewItem(ThisUserId);
            var target = CreateComponent(ThisUserId);
            await Task.Delay(30);

            MockHttp.Expect(HttpMethod.Post, "http://localhost/StarpointsManager/CreateStarpoints/-1").Respond(HttpStatusCode.OK);
            MockGetThisUserHttpRequest(ThisUserDatabaseId);
            await target.Instance.UpdateOrCreate();

            MockHttp.VerifyNoOutstandingExpectation();
        }
        public void Arrange()
        {
            Setup();

            _expected = Builder <BatchLogResponse> .CreateNew()
                        .With(q => q.BatchNumber = 12)
                        .Build();

            MockHttp.When("http://localhost:59022/api/v1/batches/latest")
            .Respond("application/json", JsonConvert.SerializeObject(_expected));     // Respond with JSON

            _result = AssessorServiceApi.GetCurrentBatchLog().Result;
        }
示例#19
0
        public void TestMethod1()
        {
            MockHttp.FakeHttpContext("");

            Credentials credentials = new NCAS.jasig.authentication.principal.UsernamePasswordCredentials
            {
            };

            ((UsernamePasswordCredentials)credentials).setPassword("test");
            ((UsernamePasswordCredentials)credentials).setUsername("test");

            _authenticationViaFormAction.submit(HttpContext.Current, credentials, null);
        }
示例#20
0
        public async Task the_component_should_load_users_ids_userObject()
        {
            MockHttp.Expect(HttpMethod.Get, $"http://localhost/User/GetUser/{ThisUser.Id}")
            .RespondValues(new UserObject {
                Id = 1, NumberOfpoints = 17
            });
            MockHttp.Expect(HttpMethod.Get, $"http://localhost/StarpointsManager/GetStarpoints/{ThisUser.Id}")
            .RespondValues(new[] { new StarpointsItem() });
            var target = CreateComponent(ThisUserIdParameter);
            await Task.Delay(50);

            target.Instance.User.Id.Should().Be(1);
        }
示例#21
0
        public void Arrange()
        {
            Setup();

            _emailTemplate = Builder <EMailTemplate> .CreateNew().Build();

            var templateName = EMailTemplateNames.PrintAssessorCoverLetters;

            MockHttp.When($"http://localhost:59022/api/v1/emailTemplates/{templateName}")
            .Respond("application/json", JsonConvert.SerializeObject(_emailTemplate));     // Respond with JSON

            _result = AssessorServiceApi.GetEmailTemplate(templateName).Result;
        }
示例#22
0
        public async Task if_user_id_is_strictly_positive_user_should_be_the_user_of_the_user_id()
        {
            MockHttp.Expect(HttpMethod.Get, "http://localhost/User/GetUser/17")
            .RespondValues(new UserObject {
                Id = 17, NumberOfpoints = 17
            });
            MockHttp.Expect(HttpMethod.Get, "http://localhost/StarpointsManager/GetStarpoints/17")
            .RespondValues(new[] { new StarpointsItem() });
            var target = CreateComponent(OtherUserIdParameter);
            await Task.Delay(50);

            target.Instance.UserId.Should().Be(17);
        }
示例#23
0
        public async Task when_updating_status_the_status_should_be_changed_in_component()
        {
            var starpointsItem = CreateStarpointsItem();

            Authorize(starpointsItem, false);
            MockHttp.Expect($"http://localhost/StarpointsManager/UpdateValidationStatus/-1/{starpointsItem.Id}/{ValidationState.Validated}").Respond(HttpStatusCode.OK);
            var component = CreateComponent(ComponentParameter.CreateParameter("Item", starpointsItem));

            component.WaitForState(() => component.Nodes?.Length > 0);
            await component.Instance.UpdateState(ValidationState.Validated);

            starpointsItem.ValidationState.Should().Be(ValidationState.Validated);
        }
示例#24
0
        public async Task when_the_item_have_been_load_isLoad_should_be_true()
        {
            MockHttp.Expect(HttpMethod.Get, $"http://localhost/User/GetUser/{ThisUser.Id}")
            .RespondValues(new UserObject {
                Id = 1, NumberOfpoints = 17
            });
            MockHttp.Expect(HttpMethod.Get, $"http://localhost/StarpointsManager/GetStarpoints/{ThisUser.Id}")
            .RespondValues(new[] { new StarpointsItem() });
            var target = CreateComponent(ThisUserIdParameter);
            await Task.Delay(50);

            target.Instance.IsLoad.Should().BeTrue();
        }
        public async Task ThenItShouldUpdateCertificatesInChunksOf100(int batchSize, int chunksSent)
        {
            Setup();

            var request = MockHttp.When(HttpMethod.Put, "http://localhost:59022/api/v1/certificates/*")
                          .Respond(System.Net.HttpStatusCode.OK, "application/json", "{'status' : 'Boo'}");

            var certificateResponses = Builder <CertificateResponse> .CreateListOfSize(batchSize).Build();

            await AssessorServiceApi.ChangeStatusToPrinted(1, certificateResponses);

            Assert.AreEqual(chunksSent, MockHttp.GetMatchCount(request));
        }
示例#26
0
        public async Task when_creating_an_item_the_user_should_navigate_to_createItem_page_with_userId_information()
        {
            MockHttp.Expect(HttpMethod.Get, "http://localhost/User/GetUser/17")
            .RespondValues(new UserObject {
                Id = 17, NumberOfpoints = 17
            });
            MockHttp.Expect(HttpMethod.Get, "http://localhost/StarpointsManager/GetStarpoints/17")
            .RespondValues(new[] { new StarpointsItem() });
            var target = CreateComponent(OtherUserIdParameter);
            await Task.Delay(50);

            target.Instance.CreateItem();
            HasNavigatedToUrl.Should().Be("/NewItem/17");
        }
示例#27
0
        public async Task when_adding_a_leader_the_right_startechtype_api_should_be_called()
        {
            MockHttp.Expect(HttpMethod.Get, "http://localhost/AdminLeader/Admin/GetLeaders").RespondValues(Users);
            var target = CreateComponent(StartechType, DisplayName);
            await Task.Delay(30);

            var userObjectToAdd = new UserObject {
                Id = 5, UserName = "******"
            };

            MockHttp.Expect(HttpMethod.Get, "http://localhost/AdminLeader/Admin/AddLeader/5").Respond(HttpStatusCode.OK);
            target.Instance.AddUser(userObjectToAdd);
            MockHttp.VerifyNoOutstandingExpectation();
        }
        public async Task when_creating_an_item_with_an_other_user_createItem_service_should_navigate_to_the_users_points()
        {
            InitializeHttpCallNewItem(OtherUserId);
            MockAuthorizationForStartechsWhichUserIsLeader();
            var target = CreateComponent(OtherUserId);
            var userId = (int)OtherUserId.Value;
            await Task.Delay(30);

            target.Instance.Item.Startech = Startechs.Agile;
            MockHttp.Expect(HttpMethod.Post, $"http://localhost/StarpointsManager/CreateStarpoints/{userId}").Respond(HttpStatusCode.OK);
            MockGetThisUserHttpRequest(33);
            await target.Instance.UpdateOrCreate();

            HasNavigatedToUrl.Should().Be($"/Points/{userId}");
        }
示例#29
0
        public async Task when_adding_a_leader_the_leader_list_should_be_reload()
        {
            MockHttp.Expect(HttpMethod.Get, "http://localhost/AdminLeader/Admin/GetLeaders").RespondValues(Users);
            var target = CreateComponent(StartechType, DisplayName);
            await Task.Delay(30);

            var userObjectToAdd = new UserObject {
                Id = 5, UserName = "******"
            };

            MockHttp.Expect(HttpMethod.Get, "http://localhost/AdminLeader/Admin/AddLeader/5").Respond(HttpStatusCode.OK);
            MockHttp.Expect(HttpMethod.Get, "http://localhost/AdminLeader/Admin/GetLeaders").RespondValues(Users.Union(new[] { userObjectToAdd }));
            target.Instance.AddUser(userObjectToAdd);
            target.WaitForAssertion(() => target.Nodes.QuerySelectorAll("li:contains(\"toAdd13215\")").Empty(), TimeSpan.FromMilliseconds(30));
        }
        public async Task when_updating_an_item_with_an_other_user_updateItem_service_should_be_called_with_the_user_id()
        {
            const int userId = 17;

            InitializeHttpCallUpdateItem(11, userId);
            MockAuthorizationForStartechsWhichUserIsLeader();
            var target = CreateComponent(TestItemId);
            await Task.Delay(30);

            target.Instance.Item.Startech = Startechs.Agile;
            MockHttp.Expect(HttpMethod.Post, $"http://localhost/StarpointsManager/UpdateStarpoints/{userId}").Respond(HttpStatusCode.OK);
            MockGetThisUserHttpRequest(userId);
            await target.Instance.UpdateOrCreate();

            MockHttp.VerifyNoOutstandingExpectation();
        }