public void Add_Option_Without_Text_Error()
        {
            Mock <IOptionRepository> mockRepository = new Mock <IOptionRepository>(MockBehavior.Strict);

            Option option = new Option();

            option.Text = null;
            mockRepository.Setup(s => s.Add(option))
            .Throws(new ArgumentNullException(nameof(option.Text)));

            option.Text = String.Empty;
            mockRepository.Setup(s => s.Add(option))
            .Throws(new ArgumentNullException(nameof(option.Text)));

            OptionService service = new OptionService(mockRepository.Object);

            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => service.Add(null));

            Assert.NotNull(ex);
            Assert.Equal(nameof(option.Text), ex.ParamName);

            ex = Assert.Throws <ArgumentNullException>(() => service.Add(String.Empty));
            Assert.NotNull(ex);
            Assert.Equal(nameof(option.Text), ex.ParamName);

            mockRepository.Verify(m => m.Add(It.IsAny <Option>()), Times.AtLeast(2));
        }
        public void Add_Option_Success()
        {
            string text = "Add_Option_Success";
            Mock <IOptionRepository> mockRepository = new Mock <IOptionRepository>(MockBehavior.Strict);

            Option newOption = new Option();

            newOption.Text = text;

            mockRepository.Setup(s => s.Add(newOption))
            .Callback <Option>(o => o.Id = 1);

            Option expected = new Option();

            expected.Id   = 1;
            expected.Text = text;

            OptionService service = new OptionService(mockRepository.Object);
            var           actual  = service.Add(text);

            Assert.NotNull(actual);
            Assert.Equal(expected, actual);
            mockRepository.Verify(m => m.Add(It.IsAny <Option>()), Times.Once());
        }
        public void Add_Option_With_Text_Greater_Than_Max_Size_Error()
        {
            Mock <IOptionRepository> mockRepository = new Mock <IOptionRepository>(MockBehavior.Strict);

            Option option = new Option();

            option.Text = new String('A', 201);

            mockRepository.Setup(s => s.Add(option))
            .Throws(new ArgumentOutOfRangeException(nameof(option.Text)));

            OptionService service = new OptionService(mockRepository.Object);

            ArgumentOutOfRangeException ex = Assert.Throws <ArgumentOutOfRangeException>(() => service.Add(option.Text));

            Assert.NotNull(ex);
            Assert.Equal(nameof(option.Text), ex.ParamName);
            mockRepository.Verify(m => m.Add(It.IsAny <Option>()), Times.Once());
        }