示例#1
0
        public ResultOperationInfo <UserInfo> GetId(int itemId)
        {
            var item     = UnitOfWork.GetRepository <User>().GetIncluding(itemId, p => p.DispatherMessages);
            var itemInfo = MapperInstance.Map <User, UserInfo>(item);

            return(new ResultOperationInfo <UserInfo>(itemInfo, true, Localization.Success_OperationComplited));
        }
示例#2
0
        public async void LoginInSystem_OK(string role)
        {
            UserDto dto = this.GetNewValidDto();

            dto.IsAdmin = false;

            var repositoryMock = this.GetNewEmptyMockedRepository();

            repositoryMock.Setup(r => r.SelectAllAsync())
            .Returns(Task.FromResult((IEnumerable <UserEntity>) new List <UserEntity> {
                MapperInstance.Map <UserEntity>(dto)
            }))
            .Verifiable();

            repositoryMock.Setup(r => r.SelectIncludingSystems(It.IsAny <string>()))
            .Returns(MapperInstance.Map <UserEntity>(dto))
            .Verifiable();

            var serviceMock = this.GetNewService(repositoryMock.Object, role);

            var obtainedDto = await serviceMock.Service.LoginInSystemAsync(this.GetNewValidLoginDto(), "MockSystem");

            serviceMock.MockUnitOfWork.VerifyAll();
            obtainedDto.Should().NotBeNull();
            obtainedDto.Id.Should().Be(dto.Id);
            obtainedDto.Name.Should().Be(dto.Name);
            obtainedDto.Role.Should().Be(role);
            obtainedDto.Token.Should().NotBeNullOrEmpty();
        }
示例#3
0
        public void GetWithUsers_GetOne()
        {
            SystemDto systemDto = this.GetNewValidDto();
            UserDto   userDto   = GetValidUserDto();

            SystemEntity entity = MapperInstance.Map <SystemEntity>(systemDto);

            entity.UserSystemLst.Add(new UserSystemEntity
            {
                SystemId = systemDto.Id,
                System   = entity,
                UserId   = userDto.Id,
                User     = MapperInstance.Map <UserEntity>(userDto)
            });

            var repositoryMock = this.GetNewEmptyMockedRepository();

            repositoryMock.Setup(r => r.SelectIncludingUsers(It.IsAny <string>()))
            .Returns(entity);
            var serviceMock = this.GetNewService(repositoryMock.Object);

            var obtainedDto = serviceMock.Service.GetWithUsers(systemDto.Id);

            serviceMock.MockUnitOfWork.Verify(mock => mock.Systems.SelectIncludingUsers(It.IsAny <string>()), Times.Once);
            obtainedDto.Should().NotBeNull();
            obtainedDto.Users.Should().NotBeNull();
            obtainedDto.Users.Should().HaveCount(1);
            obtainedDto.Id.Should().Be(systemDto.Id);
            obtainedDto.Users.First().UserId.Should().Be(userDto.Id);
        }
示例#4
0
        public void ShouldMapDifferentlyUsingMultipleMapperInstances()
        {
            var mapper1 = new MapperInstance();
            var mapper2 = new MapperInstance();

            Mapper.AddMap <Customer, Customer>(o => (Customer) new Customer().InjectFrom(o));
            mapper1.AddMap <Customer, Customer>(o => new Customer {
                Id = 1, FirstName = "mapper1"
            });
            mapper2.AddMap <Customer, Customer>(o => new Customer {
                Id = 2, FirstName = "mapper2"
            });

            var customer = GetCustomer();

            var m1 = mapper1.Map <Customer>(customer);
            var m2 = mapper2.Map <Customer>(customer);
            var m  = Mapper.Map <Customer>(customer);

            Assert.AreEqual(customer.Id, m.Id);
            Assert.AreEqual(1, m1.Id);
            Assert.AreEqual("mapper1", m1.FirstName);
            Assert.AreEqual(2, m2.Id);
            Assert.AreEqual("mapper2", m2.FirstName);
        }
        public ResultOperationInfo <IEnumerable <ClientMessageInfo> > GetAll()
        {
            var collection     = UnitOfWork.GetRepository <ClientMessage>().GetAllIncluding(p => p.Client);
            var collectionInfo = MapperInstance.Map <IEnumerable <ClientMessage>, IEnumerable <ClientMessageInfo> >(collection);

            return(new ResultOperationInfo <IEnumerable <ClientMessageInfo> >(collectionInfo, true, Localization.Success_OperationComplited));
        }
示例#6
0
        public ResultOperationInfo <CheckStatusInfo> GetId(int itemId)
        {
            var item     = UnitOfWork.GetRepository <CheckStatus>().GetIncluding(itemId);
            var itemInfo = MapperInstance.Map <CheckStatus, CheckStatusInfo>(item);

            return(new ResultOperationInfo <CheckStatusInfo>(itemInfo, true, Localization.Success_OperationComplited));
        }
        public ResultOperationInfo <IEnumerable <WorkTimeDispatcherInfo> > GetAll()
        {
            var collection     = UnitOfWork.GetRepository <WorkTimeDispatcher>().GetAllIncluding();
            var collectionInfo = MapperInstance.Map <IEnumerable <WorkTimeDispatcher>, IEnumerable <WorkTimeDispatcherInfo> >(collection);

            return(new ResultOperationInfo <IEnumerable <WorkTimeDispatcherInfo> >(collectionInfo, true, Localization.Success_OperationComplited));
        }
        public ResultOperationInfo <ClientMessageInfo> GetId(int itemId)
        {
            var item     = UnitOfWork.GetRepository <ClientMessage>().GetIncluding(itemId, p => p.Client);
            var itemInfo = MapperInstance.Map <ClientMessage, ClientMessageInfo>(item);

            return(new ResultOperationInfo <ClientMessageInfo>(itemInfo, true, Localization.Success_OperationComplited));
        }
示例#9
0
        public void MapperInstance()
        {
            var customer = GetCustomer();

            var mapper1 = new MapperInstance();
            var mapper2 = new MapperInstance();

            mapper1.AddMap <Customer, CustomerInput>((from) =>
            {
                var input = new CustomerInput();
                input.InjectFrom(from);
                return(input);
            });

            mapper2.AddMap <Customer, CustomerInput>((from) =>
            {
                var input       = new CustomerInput();
                input.FirstName = from.FirstName;
                return(input);
            });

            var input1 = mapper1.Map <CustomerInput>(customer);
            var input2 = mapper2.Map <CustomerInput>(customer);

            Assert.AreEqual(customer.LastName, input1.LastName);
            Assert.AreEqual(null, input2.LastName);
        }
示例#10
0
        public async void LoginAsAdmin_OK()
        {
            UserDto dto = this.GetNewValidDto();

            dto.IsAdmin = true;

            var repositoryMock = this.GetNewEmptyMockedRepository();

            repositoryMock.Setup(r => r.SelectAllAsync())
            .Returns(Task.FromResult(
                         (IEnumerable <UserEntity>) new List <UserEntity> {
                MapperInstance.Map <UserEntity>(dto)
            })
                     )
            .Verifiable();

            var serviceMock = this.GetNewService(repositoryMock.Object);

            var obtainedDto = await serviceMock.Service.LoginAsAdminAsync(this.GetNewValidLoginDto());

            serviceMock.MockUnitOfWork.VerifyAll();
            obtainedDto.Should().NotBeNull();
            obtainedDto.Id.Should().Be(dto.Id);
            obtainedDto.Name.Should().Be(dto.Name);
            obtainedDto.Role.Should().Be(UserRole.Admin.ToString());
            obtainedDto.Token.Should().NotBeNullOrEmpty();
        }
示例#11
0
 public async Task AddItemsAsync(IEnumerable <CustomerItem> customerItems)
 {
     foreach (var customerItem in customerItems)
     {
         var customer = MapperInstance.Map <CustomerItem, Customer>(customerItem);
         await CustomerRepository.AddItemAsync(customer);
     }
 }
        public ResultOperationInfo Update(ClientMessageInfo itemInfo)
        {
            var item        = MapperInstance.Map <ClientMessageInfo, ClientMessage>(itemInfo);
            var updatedItem = UnitOfWork.GetRepository <ClientMessage>().Update(item, item.Id);

            return(updatedItem == null
                ? new ResultOperationInfo(false, Localization.Error_OperationComplited)
                : new ResultOperationInfo(true, Localization.Success_OperationComplited));
        }
示例#13
0
        public ResultOperationInfo Add(CheckStatusInfo itemInfo)
        {
            var item      = MapperInstance.Map <CheckStatusInfo, CheckStatus>(itemInfo);
            var addedItem = UnitOfWork.GetRepository <CheckStatus>().Add(item);

            return(addedItem == null
                ? new ResultOperationInfo(false, Localization.Error_OperationComplited)
                : new ResultOperationInfo(true, Localization.Success_OperationComplited));
        }
        public ResultOperationInfo <ChannelsInfo> Create(ChannelsInfo itemInfo)
        {
            var item          = MapperInstance.Map <ChannelsInfo, Channels>(itemInfo);
            var addedItem     = UnitOfWork.GetRepository <Channels>().Add(item);
            var addedItemInfo = MapperInstance.Map <Channels, ChannelsInfo>(addedItem);

            return(addedItem == null
                ? new ResultOperationInfo <ChannelsInfo>(null, false, Localization.Error_OperationComplited)
                : new ResultOperationInfo <ChannelsInfo>(addedItemInfo, true, Localization.Success_OperationComplited));
        }
示例#15
0
        public ResultOperationInfo Add(DispatcherMessageInfo itemInfo)
        {
            var item = MapperInstance.Map <DispatcherMessageInfo, DispatherMessage>(itemInfo);

            item.User = null;
            var addedItem = UnitOfWork.GetRepository <DispatherMessage>().Add(item);

            return(addedItem == null
                ? new ResultOperationInfo(false, Localization.Error_OperationComplited)
                : new ResultOperationInfo(true, Localization.Success_OperationComplited));
        }
示例#16
0
        public ResultOperationInfo <UserInfo> Create(UserInfo itemInfo)
        {
            var item = MapperInstance.Map <UserInfo, User>(itemInfo);

            item.DispatherMessages = null;
            var addedItem     = UnitOfWork.GetRepository <User>().Add(item);
            var addedItemInfo = MapperInstance.Map <User, UserInfo>(addedItem);

            return(addedItem == null
                ? new ResultOperationInfo <UserInfo>(null, false, Localization.Error_OperationComplited)
                : new ResultOperationInfo <UserInfo>(addedItemInfo, true, Localization.Success_OperationComplited));
        }
示例#17
0
 public UserServiceSystemTest()
 {
     _user                 = this.GetNewValidDto();
     _system               = this.GetNewValidSystemDto();
     _userEntity           = MapperInstance.Map <UserEntity>(_user);
     _systemEntity         = MapperInstance.Map <SystemEntity>(_system);
     _userEntityWithSystem = MapperInstance.Map <UserEntity>(_user);
     _userEntityWithSystem.UserSystemLst.Add(new UserSystemEntity()
     {
         SystemId = _system.Id,
         UserId   = _user.Id,
         System   = _systemEntity,
         User     = _userEntity
     });
     this.SetupRepository();
 }
        public void MapMethod3()
        {
            MappingConfiguration.Add <XtoYConfiguration>();
            MappingConfiguration.Build();

            var x = new X()
            {
                X1 = 1,
                X2 = 2
            };

            IMapper mapper = new MapperInstance();
            var     y      = (Y)mapper.Map(x, typeof(X), typeof(Y));

            y.Y1.Should().Be(x.X1);
            y.Y2.Should().Be(x.X2);
        }
示例#19
0
        public async void GetByIdAsync_GetOne()
        {
            SystemDto dto            = this.GetNewValidDto();
            var       repositoryMock = this.GetNewEmptyMockedRepository();

            repositoryMock.Setup(r => r.SelectByIdAsync(It.IsAny <object[]>()))
            .Returns(new ValueTask <SystemEntity>(MapperInstance.Map <SystemEntity>(dto)));
            var serviceMock = this.GetNewService(repositoryMock.Object);

            var obtainedDto = await serviceMock.Service.GetByIdAsync(new object[] { dto.Id });

            serviceMock.MockUnitOfWork.Verify(mock => mock.Systems.SelectByIdAsync(It.IsAny <object[]>()), Times.Once);
            obtainedDto.Should().NotBeNull();
            obtainedDto.Id.Should().Be(dto.Id);
            obtainedDto.Name.Should().Be(dto.Name);
            obtainedDto.Description.Should().Be(dto.Description);
        }
        public void MapMethod2()
        {
            MappingConfiguration.Add <XtoYConfiguration>();
            MappingConfiguration.Build();

            var x = new X()
            {
                X1 = 1,
                X2 = 2
            };

            IMapper mapper = new MapperInstance();
            var     y      = mapper.Map <X, Y>(x);

            y.Y1.Should().Be(x.X1);
            y.Y2.Should().Be(x.X2);
        }
示例#21
0
        protected async Task <TAlternateSingleDto> RunAlternateRequestAndDispatchEventAsync <TRequest, TDefinition, TAlternateSingleDto, TAlternateDomain>(Func <TDefinition, TAlternateDomain> func, TRequest request, string className, CancellationToken cancellationToken)
            where TAlternateDomain : BaseDomainEventHandler <TId>
            where TAlternateSingleDto : class
        {
            var timer = new Stopwatch();

            timer.Start();

            try
            {
                var definition = MapperInstance.Map <TRequest, TDefinition>(request);
                return(await GetAlternateSingleDtoAndEvaluateEvents <TAlternateSingleDto, TAlternateDomain>(() => func(definition), cancellationToken));
            }

            finally
            {
                timer.Stop();
                Log.Debug(LogMessage(className, timer));
            }
        }
示例#22
0
        private async Task <TAlternateSingleDto> GetAlternateSingleDtoAndEvaluateEvents <TAlternateSingleDto, TAlternateDomain>(Func <TAlternateDomain> func, CancellationToken cancellationToken)
            where TAlternateDomain : BaseDomainEventHandler <TId>
            where TAlternateSingleDto : class
        {
            //TODO: Add exception for null func
            var domain = await Task.Run(func, cancellationToken);

            if (domain == null)
            {
                return(null);
            }

            var events = domain.Events;

            if (_eventDispatcher != null && events?.Any() == true)
            {
                _eventDispatcher.Dispatch(events);
            }

            return(MapperInstance.Map <TAlternateDomain, TAlternateSingleDto>(domain));
        }
示例#23
0
        public async void GetAllAsync_GetOne()
        {
            SystemDto dto            = this.GetNewValidDto();
            var       repositoryMock = this.GetNewEmptyMockedRepository();

            repositoryMock.Setup(r => r.SelectAllAsync())
            .Returns(Task.FromResult(
                         (IEnumerable <SystemEntity>) new List <SystemEntity> {
                MapperInstance.Map <SystemEntity>(dto)
            })
                     )
            .Verifiable();
            var serviceMock = this.GetNewService(repositoryMock.Object);

            var dtos = await serviceMock.Service.GetAllAsync();

            serviceMock.MockUnitOfWork.VerifyAll();
            serviceMock.MockCache.Verify(mock => mock.GetAsync <IEnumerable <SystemEntity> >(It.IsAny <string>()), Times.Once);
            serviceMock.MockCache.Verify(mock => mock.AddAsync(It.IsAny <string>(), It.IsAny <IEnumerable <SystemEntity> >()), Times.Once);
            dtos.Should().NotBeNull();
            dtos.Should().HaveCount(1);
        }
示例#24
0
        /// <summary>
        /// 数据传输对象测试
        /// </summary>
        public void DtoTest()
        {
            Console.WriteLine("******************************使用ValueInjecter实现值注入*******************************************");
            Omu.ValueInjecter.Mapper.AddMap <Student, StudentDto>(src =>
            {
                var name = "test";
                var dto  = new StudentDto
                {
                    id   = src.id,
                    name = $"{src.fname}{src.lname}"
                };
                return(dto);
            });
            var users1 = Omu.ValueInjecter.Mapper.Map <Student, StudentDto>(new Students().stus.First());

            Omu.ValueInjecter.Mapper.AddMap <Student, StudentDto>((src, tag) =>
            {
                var par = (Nametest)tag;
                var res = new StudentDto {
                    name = par.Name
                };
                return(res);
            });
            var users2 = Omu.ValueInjecter.Mapper.Map <StudentDto>(new Students().stus.First(), new Nametest {
                Name = "help"
            });

            var mapper1 = new MapperInstance();

            mapper1.AddMap <Student, Student>(o => new Student {
                fname = "mapper1"
            });

            var         users3 = mapper1.Map <Student>(new Students().stus.First());
            TextMessage msg    = new TextMessage();
            var         s      = msg.InjectFrom <XmlStrInjection>(MsgDemo1);
        }
示例#25
0
        public async void GetItemsByNameFilter_GetOne()
        {
            UserDto dto            = this.GetNewValidDto();
            var     repositoryMock = this.GetNewEmptyMockedRepository();

            repositoryMock.Setup(r => r.SelectAllAsync())
            .Returns(Task.FromResult(
                         (IEnumerable <UserEntity>) new List <UserEntity> {
                MapperInstance.Map <UserEntity>(dto)
            })
                     )
            .Verifiable();
            var serviceMock = this.GetNewService(repositoryMock.Object);

            var obtainedDtos = await serviceMock.Service.GetItemsByNameFilter(dto.Name);

            serviceMock.MockUnitOfWork.VerifyAll();
            serviceMock.MockCache.Verify(mock => mock.GetAsync <IEnumerable <UserEntity> >(It.IsAny <string>()), Times.Once);
            serviceMock.MockCache.Verify(mock => mock.AddAsync(It.IsAny <string>(), It.IsAny <IEnumerable <UserEntity> >()), Times.Once);
            obtainedDtos.Should().NotBeNull();
            obtainedDtos.Should().HaveCount(1);
            obtainedDtos.First().UserId.Should().Be(dto.Id);
            obtainedDtos.First().Name.Should().Be(dto.Name);
        }
        public static T Map <T>(object source)
        {
            Log.Debug("Starting to copy/map object: " + source);

            if (source == null)
            {
                return(default(T));
            }
            var mappedObject = MapperObject.Map <T>(source);

            Log.Debug("Mapped objected is: " + source);
            return(mappedObject);
        }
示例#27
0
        public async Task <IEnumerable <CustomerNameListItem> > FetchCustomerNamesAsync()
        {
            var customerItems = await CustomerRepository.FetchAllAsync();

            return(MapperInstance.Map <ICollection <Customer>, ICollection <CustomerNameListItem> >(customerItems));
        }
示例#28
0
        public async Task UpdateWithoutPasswordAsync(AppUserActionVm userActionVm)
        {
            var appUserUpdateVm = MapperInstance.Map <AppUserUpdateVm>(userActionVm.AppUserDto);

            await UpdateCustomVmAsync(appUserUpdateVm);
        }
示例#29
0
        public void ShouldMapDifferentlyUsingMultipleMapperInstances()
        {
            var mapper1 = new MapperInstance();
            var mapper2 = new MapperInstance();

            Mapper.AddMap<Customer, Customer>(o => (Customer)new Customer().InjectFrom(o));
            mapper1.AddMap<Customer, Customer>(o => new Customer { Id = 1, FirstName = "mapper1" });
            mapper2.AddMap<Customer, Customer>(o => new Customer { Id = 2, FirstName = "mapper2" });

            var customer = GetCustomer();

            var m1 = mapper1.Map<Customer>(customer);
            var m2 = mapper2.Map<Customer>(customer);
            var m = Mapper.Map<Customer>(customer);

            Assert.AreEqual(customer.Id, m.Id);
            Assert.AreEqual(1, m1.Id);
            Assert.AreEqual("mapper1", m1.FirstName);
            Assert.AreEqual(2, m2.Id);
            Assert.AreEqual("mapper2", m2.FirstName);
        }
示例#30
0
 public static TResult Map <TResult>(object source, object tag = null)
 {
     return(Instance.Map <TResult>(source, tag));
 }