示例#1
0
        public void CQRSProjections()
        {
            FakeCommandDto fcDto = new FakeCommandDto();

            fcDto.TestString = "Testing";
            FakeCommand fc = fcDto.ProjectAsCommand <FakeCommandDto, FakeCommand>();

            Assert.AreEqual <string>(fc.TestString, fcDto.TestString, "Same Projection Id To DTO");


            fc.TestString = "String changed";
            fcDto         = fc.ProjectAsDto <FakeCommand, FakeCommandDto>();
            Assert.AreEqual <string>(fc.TestString, fcDto.TestString, "Same Projection Id From DTO");


            fc.TestString = "Testing collection";
            List <FakeCommand> commands = new List <FakeCommand>();

            commands.Add(fc);
            var dtos = new List <FakeCommandDto>(commands.ProjectAsDto <FakeCommand, FakeCommandDto>());

            Assert.AreEqual <string>(commands[0].TestString, dtos[0].TestString, "Same Projection Id To Collection DTO");


            fcDto.TestString = "String collection changed";
            List <FakeCommandDto> fakeDTOs = new List <FakeCommandDto>();

            fakeDTOs.Add(fcDto);
            List <FakeCommand> fakeCommands = new List <FakeCommand>(fakeDTOs.ProjectAsCommand <FakeCommandDto, FakeCommand>());

            Assert.AreEqual <string>(commands[0].TestString, dtos[0].TestString, "Same Projection Id From Collection DTO");


            var fcdto = fc.ProjectAsDto <FakeCommand, FakeCommandDto>(CustomConvertToDTO);

            Assert.AreEqual <string>(fcdto.TestString, "As Dto", "Same custom Projection string From DTO");

            fc = fcdto.ProjectAsCommand <FakeCommandDto, FakeCommand>(CustomConvertToCommand);
            Assert.AreEqual <string>(fc.TestString, "As Command", "Same custom Projection string From command");

            dtos = new List <FakeCommandDto>(commands.ProjectAsDto <FakeCommand, FakeCommandDto>(CustomConvertToDTO));
            Assert.AreEqual <string>(dtos[0].TestString, "As Dto", "Same custom Projection string From DTO");

            fakeCommands = new List <FakeCommand>(fakeDTOs.ProjectAsCommand <FakeCommandDto, FakeCommand>(CustomConvertToCommand));
            Assert.AreEqual <string>(fakeCommands[0].TestString, "As Command", "Same custom Projection Id From Collection DTO");
        }
示例#2
0
 public FakeCommandDto CustomConvertToDTO(FakeCommandDto command, object state)
 {
     command.TestString = "As Dto";
     return(command);
 }