Beispiel #1
0
        public void MapEntityToModelList()
        {
            var mapper            = new DALTestAllFieldTypeMapper();
            TestAllFieldType item = new TestAllFieldType();

            item.SetProperties(1, 1, BitConverter.GetBytes(1), true, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), 1m, 1, BitConverter.GetBytes(1), 1m, "A", "A", 1m, "A", 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1m, "A", TimeSpan.Parse("01:00:00"), BitConverter.GetBytes(1), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), BitConverter.GetBytes(1), "A", "A");
            List <ApiTestAllFieldTypeServerResponseModel> response = mapper.MapEntityToModel(new List <TestAllFieldType>()
            {
                { item }
            });

            response.Count.Should().Be(1);
        }
        public virtual async Task <ApiTestAllFieldTypeServerResponseModel> Get(int id)
        {
            TestAllFieldType record = await this.TestAllFieldTypeRepository.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                return(this.DalTestAllFieldTypeMapper.MapEntityToModel(record));
            }
        }
        public void MapEFToBOList()
        {
            var mapper = new DALTestAllFieldTypeMapper();
            TestAllFieldType entity = new TestAllFieldType();

            entity.SetProperties(1, BitConverter.GetBytes(1), true, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), 1, 1, BitConverter.GetBytes(1), 1m, "A", "A", 1m, "A", 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1m, "A", TimeSpan.Parse("0"), BitConverter.GetBytes(1), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), BitConverter.GetBytes(1), "A", "A", 1);

            List <BOTestAllFieldType> response = mapper.MapEFToBO(new List <TestAllFieldType>()
            {
                entity
            });

            response.Count.Should().Be(1);
        }
        public virtual async Task <CreateResponse <ApiTestAllFieldTypeServerResponseModel> > Create(
            ApiTestAllFieldTypeServerRequestModel model)
        {
            CreateResponse <ApiTestAllFieldTypeServerResponseModel> response = ValidationResponseFactory <ApiTestAllFieldTypeServerResponseModel> .CreateResponse(await this.TestAllFieldTypeModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                TestAllFieldType record = this.DalTestAllFieldTypeMapper.MapModelToEntity(default(int), model);
                record = await this.TestAllFieldTypeRepository.Create(record);

                response.SetRecord(this.DalTestAllFieldTypeMapper.MapEntityToModel(record));
                await this.mediator.Publish(new TestAllFieldTypeCreatedNotification(response.Record));
            }

            return(response);
        }
        public async void Get()
        {
            var mock   = new ServiceMockFacade <ITestAllFieldTypeRepository>();
            var record = new TestAllFieldType();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record));
            var service = new TestAllFieldTypeService(mock.LoggerMock.Object,
                                                      mock.RepositoryMock.Object,
                                                      mock.ModelValidatorMockFactory.TestAllFieldTypeModelValidatorMock.Object,
                                                      mock.BOLMapperMockFactory.BOLTestAllFieldTypeMapperMock,
                                                      mock.DALMapperMockFactory.DALTestAllFieldTypeMapperMock);

            ApiTestAllFieldTypeResponseModel response = await service.Get(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public void MapEFToBO()
        {
            var mapper = new DALTestAllFieldTypeMapper();
            TestAllFieldType entity = new TestAllFieldType();

            entity.SetProperties(1, BitConverter.GetBytes(1), true, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), 1, 1, BitConverter.GetBytes(1), 1m, "A", "A", 1m, "A", 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1m, "A", TimeSpan.Parse("0"), BitConverter.GetBytes(1), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), BitConverter.GetBytes(1), "A", "A", 1);

            BOTestAllFieldType response = mapper.MapEFToBO(entity);

            response.FieldBigInt.Should().Be(1);
            response.FieldBinary.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.FieldBit.Should().Be(true);
            response.FieldChar.Should().Be("A");
            response.FieldDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.FieldDateTime.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.FieldDateTime2.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.FieldDateTimeOffset.Should().Be(DateTimeOffset.Parse("1/1/1987 12:00:00 AM"));
            response.FieldDecimal.Should().Be(1);
            response.FieldFloat.Should().Be(1);
            response.FieldImage.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.FieldMoney.Should().Be(1m);
            response.FieldNChar.Should().Be("A");
            response.FieldNText.Should().Be("A");
            response.FieldNumeric.Should().Be(1m);
            response.FieldNVarchar.Should().Be("A");
            response.FieldReal.Should().Be(1m);
            response.FieldSmallDateTime.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.FieldSmallInt.Should().Be(1);
            response.FieldSmallMoney.Should().Be(1m);
            response.FieldText.Should().Be("A");
            response.FieldTime.Should().Be(TimeSpan.Parse("0"));
            response.FieldTimestamp.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.FieldTinyInt.Should().Be(1);
            response.FieldUniqueIdentifier.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.FieldVarBinary.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.FieldVarchar.Should().Be("A");
            response.FieldXML.Should().Be("A");
            response.Id.Should().Be(1);
        }
        public virtual TestAllFieldType MapModelToEntity(
            int id,
            ApiTestAllFieldTypeServerRequestModel model
            )
        {
            TestAllFieldType item = new TestAllFieldType();

            item.SetProperties(
                id,
                model.FieldBigInt,
                model.FieldBinary,
                model.FieldBit,
                model.FieldChar,
                model.FieldDate,
                model.FieldDateTime,
                model.FieldDateTime2,
                model.FieldDateTimeOffset,
                model.FieldDecimal,
                model.FieldFloat,
                model.FieldImage,
                model.FieldMoney,
                model.FieldNChar,
                model.FieldNText,
                model.FieldNumeric,
                model.FieldNVarchar,
                model.FieldReal,
                model.FieldSmallDateTime,
                model.FieldSmallInt,
                model.FieldSmallMoney,
                model.FieldText,
                model.FieldTime,
                model.FieldTimestamp,
                model.FieldTinyInt,
                model.FieldUniqueIdentifier,
                model.FieldVarBinary,
                model.FieldVarchar,
                model.FieldXML);
            return(item);
        }
        public virtual async Task <UpdateResponse <ApiTestAllFieldTypeServerResponseModel> > Update(
            int id,
            ApiTestAllFieldTypeServerRequestModel model)
        {
            var validationResult = await this.TestAllFieldTypeModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                TestAllFieldType record = this.DalTestAllFieldTypeMapper.MapModelToEntity(id, model);
                await this.TestAllFieldTypeRepository.Update(record);

                record = await this.TestAllFieldTypeRepository.Get(id);

                ApiTestAllFieldTypeServerResponseModel apiModel = this.DalTestAllFieldTypeMapper.MapEntityToModel(record);
                await this.mediator.Publish(new TestAllFieldTypeUpdatedNotification(apiModel));

                return(ValidationResponseFactory <ApiTestAllFieldTypeServerResponseModel> .UpdateResponse(apiModel));
            }
            else
            {
                return(ValidationResponseFactory <ApiTestAllFieldTypeServerResponseModel> .UpdateResponse(validationResult));
            }
        }
Beispiel #9
0
        public virtual BOTestAllFieldType MapEFToBO(
            TestAllFieldType ef)
        {
            var bo = new BOTestAllFieldType();

            bo.SetProperties(
                ef.Id,
                ef.FieldBigInt,
                ef.FieldBinary,
                ef.FieldBit,
                ef.FieldChar,
                ef.FieldDate,
                ef.FieldDateTime,
                ef.FieldDateTime2,
                ef.FieldDateTimeOffset,
                ef.FieldDecimal,
                ef.FieldFloat,
                ef.FieldImage,
                ef.FieldMoney,
                ef.FieldNChar,
                ef.FieldNText,
                ef.FieldNumeric,
                ef.FieldNVarchar,
                ef.FieldReal,
                ef.FieldSmallDateTime,
                ef.FieldSmallInt,
                ef.FieldSmallMoney,
                ef.FieldText,
                ef.FieldTime,
                ef.FieldTimestamp,
                ef.FieldTinyInt,
                ef.FieldUniqueIdentifier,
                ef.FieldVarBinary,
                ef.FieldVarchar,
                ef.FieldXML);
            return(bo);
        }
Beispiel #10
0
        public virtual TestAllFieldType MapBOToEF(
            BOTestAllFieldType bo)
        {
            TestAllFieldType efTestAllFieldType = new TestAllFieldType();

            efTestAllFieldType.SetProperties(
                bo.FieldBigInt,
                bo.FieldBinary,
                bo.FieldBit,
                bo.FieldChar,
                bo.FieldDate,
                bo.FieldDateTime,
                bo.FieldDateTime2,
                bo.FieldDateTimeOffset,
                bo.FieldDecimal,
                bo.FieldFloat,
                bo.FieldImage,
                bo.FieldMoney,
                bo.FieldNChar,
                bo.FieldNText,
                bo.FieldNumeric,
                bo.FieldNVarchar,
                bo.FieldReal,
                bo.FieldSmallDateTime,
                bo.FieldSmallInt,
                bo.FieldSmallMoney,
                bo.FieldText,
                bo.FieldTime,
                bo.FieldTimestamp,
                bo.FieldTinyInt,
                bo.FieldUniqueIdentifier,
                bo.FieldVarBinary,
                bo.FieldVarchar,
                bo.FieldXML,
                bo.Id);
            return(efTestAllFieldType);
        }
        public virtual ApiTestAllFieldTypeServerResponseModel MapEntityToModel(
            TestAllFieldType item)
        {
            var model = new ApiTestAllFieldTypeServerResponseModel();

            model.SetProperties(item.Id,
                                item.FieldBigInt,
                                item.FieldBinary,
                                item.FieldBit,
                                item.FieldChar,
                                item.FieldDate,
                                item.FieldDateTime,
                                item.FieldDateTime2,
                                item.FieldDateTimeOffset,
                                item.FieldDecimal,
                                item.FieldFloat,
                                item.FieldImage,
                                item.FieldMoney,
                                item.FieldNChar,
                                item.FieldNText,
                                item.FieldNumeric,
                                item.FieldNVarchar,
                                item.FieldReal,
                                item.FieldSmallDateTime,
                                item.FieldSmallInt,
                                item.FieldSmallMoney,
                                item.FieldText,
                                item.FieldTime,
                                item.FieldTimestamp,
                                item.FieldTinyInt,
                                item.FieldUniqueIdentifier,
                                item.FieldVarBinary,
                                item.FieldVarchar,
                                item.FieldXML);

            return(model);
        }