Ejemplo n.º 1
0
        public virtual async void TestCreate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            var model = new ApiTeacherClientRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", "B", "B", "B", 1);
            CreateResponse <ApiTeacherClientResponseModel> result = await client.TeacherCreateAsync(model);

            result.Success.Should().BeTrue();
            result.Record.Should().NotBeNull();
            context.Set <Teacher>().ToList()[1].Birthday.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Teacher>().ToList()[1].Email.Should().Be("B");
            context.Set <Teacher>().ToList()[1].FirstName.Should().Be("B");
            context.Set <Teacher>().ToList()[1].LastName.Should().Be("B");
            context.Set <Teacher>().ToList()[1].Phone.Should().Be("B");
            context.Set <Teacher>().ToList()[1].UserId.Should().Be(1);

            result.Record.Birthday.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            result.Record.Email.Should().Be("B");
            result.Record.FirstName.Should().Be("B");
            result.Record.LastName.Should().Be("B");
            result.Record.Phone.Should().Be("B");
            result.Record.UserId.Should().Be(1);
        }
        public virtual ApiTeacherClientRequestModel MapServerResponseToClientRequest(
            ApiTeacherServerResponseModel response)
        {
            var request = new ApiTeacherClientRequestModel();

            request.SetProperties(
                response.Birthday,
                response.Email,
                response.FirstName,
                response.LastName,
                response.Phone,
                response.UserId);
            return(request);
        }
Ejemplo n.º 3
0
        public void MapClientResponseToRequest()
        {
            var mapper = new ApiTeacherModelMapper();
            var model  = new ApiTeacherClientResponseModel();

            model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", 1);
            ApiTeacherClientRequestModel response = mapper.MapClientResponseToRequest(model);

            response.Should().NotBeNull();
            response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Phone.Should().Be("A");
            response.UserId.Should().Be(1);
        }
Ejemplo n.º 4
0
        public virtual async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            var mapper = new ApiTeacherServerModelMapper();
            ApplicationDbContext          context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            ITeacherService               service = testServer.Host.Services.GetService(typeof(ITeacherService)) as ITeacherService;
            ApiTeacherServerResponseModel model   = await service.Get(1);

            ApiTeacherClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", "B", "B", "B", 1);

            UpdateResponse <ApiTeacherClientResponseModel> updateResponse = await client.TeacherUpdateAsync(model.Id, request);

            context.Entry(context.Set <Teacher>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Teacher>().ToList()[0].Birthday.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Teacher>().ToList()[0].Email.Should().Be("B");
            context.Set <Teacher>().ToList()[0].FirstName.Should().Be("B");
            context.Set <Teacher>().ToList()[0].LastName.Should().Be("B");
            context.Set <Teacher>().ToList()[0].Phone.Should().Be("B");
            context.Set <Teacher>().ToList()[0].UserId.Should().Be(1);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Birthday.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            updateResponse.Record.Email.Should().Be("B");
            updateResponse.Record.FirstName.Should().Be("B");
            updateResponse.Record.LastName.Should().Be("B");
            updateResponse.Record.Phone.Should().Be("B");
            updateResponse.Record.UserId.Should().Be(1);
        }