Exemple #1
0
        /// <summary>
        /// Gets Json from Resources and Transforms it into the Output format
        /// </summary>
        /// <returns>string</returns>
        public string GetLearner()
        {
            LearnerDTO   learnerDTO   = JsonFactory.LoadJson();
            LearnerModel learnerModel = mappers.LearnerDTOtoLearnerModel(learnerDTO);
            OutputModel  outputModel  = mappers.LearnerModeltoOutputModel(learnerModel);
            OutputDTO    outputDTO    = mappers.OutputModeltoOutputDTO(outputModel);

            return(JsonFactory.JsonSerialize(outputDTO));
        }
Exemple #2
0
        public void LearnerModeltoOutputModel_ShouldMapLearnerModeltoOutputModel()
        {
            //Arrange
            LearnerModel learner = new LearnerModel
            {
                LearnerId      = 456,
                Forename       = "Rosie",
                Surname        = "Toll",
                DateOfEntry    = "01/01/2021",
                AddressDetails = new List <AddressDetailModel>()
                {
                    new AddressDetailModel
                    {
                        Number = "456", Street = "Test Street", PostCode = "LL34 6NG"
                    }
                },
                Year = "9"
            };
            OutputModel output = new OutputModel();

            var services = new ServiceCollection();

            services.AddAutoMapper(typeof(AutoMapping));
            services.AddTransient <IMappers, Mappers>();

            IServiceProvider serviceProvider = services.BuildServiceProvider();
            IMappers         mappers         = serviceProvider.GetRequiredService <IMappers>();

            //Act
            output = mappers.LearnerModeltoOutputModel(learner);

            //Assert
            Assert.NotNull(output);
            Assert.Equal(learner.LearnerId.ToString(), output.source_id);
            Assert.Equal(learner.Forename, output.first_name);
            Assert.Equal(learner.Surname, output.last_name);
            Assert.Equal(learner.DateOfEntry, output.start_date);
            Assert.Equal(learner.AddressDetails[0].Number + " " + learner.AddressDetails[0].Street, output.address_line_1);
            Assert.Equal(learner.AddressDetails[0].PostCode, output.postcode);
            Assert.Equal(learner.Year, output.year_code);
        }