public void Get_ById_Test()
        {
            //Arange
            var stubScriptService = new Mock<IScriptService>();
            var stubMapper = new Mock<IScriptMapper>();

            var script = new Script
            {
                ScriptId = 1
            };

            var transferScript = new TransferScript
            {
                ScriptId = 1
            };

            stubScriptService.Setup(ss => ss.FetchScriptById(1))
                .Returns(script);
            stubMapper.Setup(m => m.Map(script))
                .Returns(transferScript);

            var controller = new ScriptController(stubScriptService.Object,
                stubMapper.Object, new CookieParser());

            //Act
            var actual = controller.Get(1);

            //Assert
            Assert.That(actual.ScriptId == script.ScriptId);

            stubMapper.Verify(m => m.Map(script),
                Times.Once);

            stubScriptService.Verify(ss => ss.FetchScriptById(1),
                Times.Once);
        }
예제 #2
0
        public void Map_toDomain_Test()
        {
            //Arange
            var dummyRoleMapper = new RoleMapper();
            var dummyUserMapper = new UserMapper(dummyRoleMapper);
            var dummyOptionMapper = new OptionsMapper();
            var dummySectionMapper = new SectionMapper();

            IScriptMapper mapper = new ScriptMapper(dummyUserMapper, dummyOptionMapper,
                dummySectionMapper, new CookieParser());

            var script = new TransferScript
            {
                EntityState = EntityState.Unchanged,
                OperatorId = 99,
                ScriptId = 99,
                Title = "test",
                CreatedDate = new DateTime(1, 1, 1),
                LastEditedDate = new DateTime(1, 1, 1),
                OptionsId = 99,
                PrompterId = 99,
                Options = null,
                Operator = null,
                Prompter = null
            };

            var expected = new ComparableScript
            {
                EntityState = EntityState.Unchanged,
                OperatorId = 99,
                ScriptId = 99,
                Title = "test",
                CreatedDate = new DateTime(1, 1, 1),
                LastEditedDate = new DateTime(1, 1, 1),
                OptionsId = 99,
                PrompterId = 99,
                Options = null,
                Operator = null,
                Prompter = null
            };

            //Act
            var actual = mapper.Map(script);

            //Assert
            Assert.That(actual, Is.EqualTo(expected));
            Assert.That(actual.Options, Is.Null);
            Assert.That(actual.Operator, Is.Null);
            Assert.That(actual.Prompter, Is.Null);
        }