public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new PersonsClient(connection);

                var filters = new PersonSearchFilters
                {
                    ExactMatch = true,
                    PageSize   = 1,
                    PageCount  = 1,
                    StartPage  = 0,
                };

                await client.Search("name", filters);

                Received.InOrder(async() =>
                {
                    await connection.SearchAll <SearchResult <SimplePerson> >(Arg.Is <Uri>(u => u.ToString() == "persons/search"),
                                                                              Arg.Is <Dictionary <string, string> >(d => d.Count == 2 &&
                                                                                                                    d["term"] == "name" &&
                                                                                                                    d["exact_match"] == "True"),
                                                                              Arg.Is <ApiOptions>(o => o.PageSize == 1 &&
                                                                                                  o.PageCount == 1 &&
                                                                                                  o.StartPage == 0));
                });
            }
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new PersonsClient(connection);

                var filters = new PersonFilters
                {
                    PageSize  = 1,
                    PageCount = 1,
                    StartPage = 0,
                };

                await client.GetAllForUserId(123, filters);

                Received.InOrder(async() =>
                {
                    await connection.GetAll <Person>(
                        Arg.Is <Uri>(u => u.ToString() == "persons"),
                        Arg.Is <Dictionary <string, string> >(d => d.Count == 1 &&
                                                              d["user_id"] == "123"),
                        Arg.Is <ApiOptions>(o => o.PageSize == 1 &&
                                            o.PageCount == 1 &&
                                            o.StartPage == 0));
                });
            }
            public async Task EnsuresSearchTermIsMoreThan2Characters()
            {
                var client = new PersonsClient(Substitute.For <IApiConnection>());

                var exception = await Assert.ThrowsAsync <ArgumentException>(() => client.Search("p", PersonSearchFilters.None));

                Assert.Equal("The search term must have at least 2 characters (Parameter 'term')", exception.Message);
            }
Esempio n. 4
0
 public RegistrationPageModel(IUnitOfWork unitOfWork)
 {
     _uow = unitOfWork;
     _pc  = new PersonsClient();
     _sc  = new SettingsClient();
     //LastTestedDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
     //LastTestedTime = new TimeSpan(DateTime.Now.TimeOfDay.Ticks);
 }
            public void DeletesCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new PersonsClient(connection);

                client.DeleteFollower(1, 461);

                connection.Received().Delete(Arg.Is <Uri>(u => u.ToString() == "persons/1/followers/461"));
            }
            public void PostsToTheCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new PersonsClient(connection);

                client.AddFollower(1, 2);

                connection.Received().Post <PersonFollower>(Arg.Is <Uri>(u => u.ToString() == "persons/1/followers"),
                                                            Arg.Is <object>(o => o.ToString() == new { user_id = 2 }.ToString()));
            }
Esempio n. 7
0
        public async Task GetAll_SerializationTest()
        {
            //// Arrange
            var personsClient = new PersonsClient("http://localhost:13452");

            //// Act
            var persons = await personsClient.GetAllAsync();

            //// Assert
            Assert.AreEqual(2, persons.Count);
        }
Esempio n. 8
0
        public async Task GetAll_InheritanceTest()
        {
            //// Arrange
            var personsClient = new PersonsClient("http://localhost:13452");

            //// Act
            var persons = await personsClient.GetAllAsync();

            //// Assert
            Assert.AreEqual("SE", ((Teacher)persons[1]).Course); // inheritance test
        }
Esempio n. 9
0
        public async Task GetAll_InheritanceTest()
        {
            //// Arrange
            var personsClient = new PersonsClient { BaseUrl = "http://localhost:13452" };

            //// Act
            var persons = await personsClient.GetAllAsync();

            //// Assert
            Assert.AreEqual("SE", ((Teacher)persons[1]).Course); // inheritance test
        }
Esempio n. 10
0
        public async Task GetAll_SerializationTest()
        {
            //// Arrange
            var personsClient = new PersonsClient { BaseUrl = "http://localhost:13452" }; ;

            //// Act
            var persons = await personsClient.GetAllAsync();

            //// Assert
            Assert.AreEqual(2, persons.Count);
        }
            public void PostsToTheCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new PersonsClient(connection);

                var newPerson = new NewPerson("name");

                client.Create(newPerson);

                connection.Received().Post <Person>(Arg.Is <Uri>(u => u.ToString() == "persons"),
                                                    Arg.Is <NewPerson>(d => d.Name == "name"));
            }
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new PersonsClient(connection);

                await client.Get(123);

                Received.InOrder(async() =>
                {
                    await connection.Get <Person>(Arg.Is <Uri>(u => u.ToString() == "persons/123"));
                });
            }
Esempio n. 13
0
        public async Task AddXml_PostXml()
        {
            //// Arrange
            var personsClient = new PersonsClient(new HttpClient())
            {
                BaseUrl = "http://localhost:13452"
            };;

            //// Act
            var result = await personsClient.AddXmlAsync("<Rico>Suter</Rico>");

            //// Assert
        }
            public void PutsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new PersonsClient(connection);

                var editPerson = new PersonUpdate {
                    Name = "name"
                };

                client.Edit(123, editPerson);

                connection.Received().Put <Person>(Arg.Is <Uri>(u => u.ToString() == "persons/123"),
                                                   Arg.Is <PersonUpdate>(d => d.Name == "name"));
            }
Esempio n. 15
0
        public async Task When_Get_is_called_then_Teacher_is_returned()
        {
            // Arrange
            var personsClient = new PersonsClient(new HttpClient())
            {
                BaseUrl = "http://localhost:13452"
            };

            // Act
            var result = await personsClient.GetAsync(new Guid());

            // Assert
            Assert.IsTrue(result.Result.GetType() == typeof(Teacher));
        }
Esempio n. 16
0
        public async Task Get_should_return_teacher()
        {
            //// Arrange
            var personsClient = new PersonsClient(new HttpClient())
            {
                BaseUrl = "http://localhost:13452"
            };;

            //// Act
            var result = await personsClient.GetAsync(new Guid());

            //// Assert
            Assert.IsTrue(result.Result is Teacher);
        }
Esempio n. 17
0
        public async Task GetAll_InheritanceTest()
        {
            //// Arrange
            var personsClient = new PersonsClient(new HttpClient())
            {
                BaseUrl = "http://localhost:13452"
            };

            //// Act
            var persons = await personsClient.GetAllAsync();

            //// Assert
            Assert.AreEqual("SE", ((Teacher)persons.Result.ToList()[1]).Course); // inheritance test
        }
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new PersonsClient(connection);

                await client.GetByName("name");

                Received.InOrder(async() =>
                {
                    await connection.GetAll <SimplePerson>(Arg.Is <Uri>(u => u.ToString() == "persons/find"),
                                                           Arg.Is <Dictionary <string, string> >(d => d.Count == 2 &&
                                                                                                 d["term"] == "name" &&
                                                                                                 d["search_by_email"] == "0"));
                });
            }
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new PersonsClient(connection);

                await client.GetFollowers(123);

                Received.InOrder(async() =>
                {
                    await connection.GetAll <PersonFollower>(
                        Arg.Is <Uri>(u => u.ToString() == "persons/123/followers"),
                        Arg.Is <Dictionary <string, string> >(d => d.Count == 1 &&
                                                              d["id"] == "123"));
                });
            }
Esempio n. 20
0
        public async Task GetAll_SerializationTest()
        {
            //// Arrange
            var personsClient = new PersonsClient(new HttpClient())
            {
                BaseUrl = "http://localhost:13452"
            };;

            //// Act
            var persons = await personsClient.GetAllAsync();

            //// Assert
            Assert.AreEqual(2, persons.Result.Count);
            Assert.IsTrue(persons.Result.ToList()[0].GetType() == typeof(Person));
            Assert.IsTrue(persons.Result.ToList()[1].GetType() == typeof(Teacher));
        }
Esempio n. 21
0
        public async Task Throw()
        {
            //// Arrange
            var id            = Guid.NewGuid();
            var personsClient = new PersonsClient("http://localhost:13452");

            //// Act
            try
            {
                var persons = await personsClient.ThrowAsync(id);
            }
            catch (PersonsClientException <PersonNotFoundException> exception)
            {
                //// Assert
                Assert.AreEqual(id, exception.Response.Id);
            }
        }
Esempio n. 22
0
        public async Task Throw()
        {
            //// Arrange
            var id = Guid.NewGuid();
            var personsClient = new PersonsClient { BaseUrl = "http://localhost:13452" };

            //// Act
            try
            {
                var persons = await personsClient.ThrowAsync(id);
            }
            catch (PersonsClientException<PersonNotFoundException> exception)
            {
                //// Assert
                Assert.AreEqual(id, exception.Response.Id); 
            }
        }
Esempio n. 23
0
        //[TestMethod]
        //[TestCategory("integration")]
        public async Task Binary_body()
        {
            //// Arrange
            var personsClient = new PersonsClient(new HttpClient())
            {
                BaseUrl = "http://localhost:13452"
            };;

            //// Act
            var stream = new MemoryStream(new byte[] { 1, 2, 3 });
            var result = await personsClient.UploadAsync(new FileParameter(stream));

            //// Assert
            Assert.AreEqual(3, result.Result.Length);
            Assert.AreEqual(1, result.Result[0]);
            Assert.AreEqual(2, result.Result[1]);
            Assert.AreEqual(3, result.Result[2]);
        }
Esempio n. 24
0
        public async Task When_Teacher_is_sent_to_Transform_it_is_transformed_and_correctly_sent_back()
        {
            // Arrange
            var personsClient = new PersonsClient(new HttpClient())
            {
                BaseUrl = "http://localhost:13452"
            };

            // Act
            var result = await personsClient.TransformAsync(new Teacher
            {
                FirstName = "foo",
                LastName  = "bar",
                Course    = "SE"
            });

            // Assert
            Assert.IsTrue(result.Result.GetType() == typeof(Teacher));
            var teacher = (Teacher)result.Result;

            Assert.AreEqual("FOO", teacher.FirstName);
            Assert.AreEqual("SE", teacher.Course);
        }
Esempio n. 25
0
        public void Index_SendRequest_HttpDriver_ShouldReturnView()
        {
            const int                       expectedCount = 3;
            var                             webAPIPersonsControllerDriver = new WebAPI_HttpDriver_PersonsController_GetAll();
            Mock <IPersonsData>             personsDataMock = null;
            WebApplicationFactory <Startup> webHost         = new WebApplicationFactory <Startup>()
                                                              .WithWebHostBuilder(builder =>
            {
                builder.ConfigureServices(services =>
                {
                    var descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(IPersonsData));
                    services.Remove(descriptor);
                    var mockMessageHandler = new Mock <HttpMessageHandler>();
                    mockMessageHandler.Protected()
                    .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>())
                    .ReturnsAsync(() =>
                    {
                        return(webAPIPersonsControllerDriver.GetAll(expectedCount));
                    });
                    var client = new PersonsClient(new HttpClient(mockMessageHandler.Object)
                    {
                        BaseAddress = new Uri("http://localost/")
                    });

                    services.AddTransient <IPersonsData>(_ => client);
                    var delDescriptor = services.SingleOrDefault(d => d.ServiceType == typeof(IProductData));
                    services.Remove(delDescriptor);
                    services.AddTransient(_ => Mock.Of <IProductData>());
                });
            });
            var httpClient = webHost.CreateClient();

            var response = httpClient.GetAsync("persons").Result;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsTrue(webAPIPersonsControllerDriver.BeCalled);
        }
Esempio n. 26
0
 public WriteTagPageModel(IUnitOfWork unitOfWork)
 {
     _pc         = new PersonsClient();
     _sc         = new SettingsClient();
     _pipeClient = new PipeClient();
 }
        public PersonsClient_ClientServer_Test()
        {
            _factory = new BlazorWasmTestingWebApplicationFactory(_dbContextFactory);

            _personsApi = new PersonsClient(_factory.CreateClient());
        }
            public async Task EnsuresNonNullArguments()
            {
                var client = new PersonsClient(Substitute.For <IApiConnection>());

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Search(null, null));
            }
Esempio n. 29
0
 public RegistrationOverviewModel(IUnitOfWork unitOfWork)
 {
     _uow            = unitOfWork;
     _pc             = new PersonsClient();
     _settingsClient = new SettingsClient();
 }