Ejemplo n.º 1
0
        private static void RunReversedTest(AutoMock mock)
        {
            Expect.Once.On(mock.Resolve <IServiceB>()).Method("RunB");
            Expect.Once.On(mock.Resolve <IServiceA>()).Method("RunA");

            var component = mock.Create <TestComponent>();

            component.RunAll();
        }
Ejemplo n.º 2
0
        public void Does_Not_Auto_Fake_Enumerable()
        {
            AutoMock.Provide <Item>(new A());
            AutoMock.Provide <Item>(new B());

            AutoMock.Resolve <IEnumerable <Item> >().Should().HaveCount(2);
        }
Ejemplo n.º 3
0
    public void Should_Fail_If_Container_Is_Touched_When_Building()
    {
        var    access = AutoMock.Resolve <DoubleAccess>();
        Action a      = () => access.Self.Resolve <IContainer>();

        a.Should().Throw <TestBootstrapException>();
    }
Ejemplo n.º 4
0
 public void Should_Populate_Optional_Parameters_When_Provided()
 {
     AutoMock.Provide<IItem>(new MyItem());
     var optional = AutoMock.Resolve<Optional>();
     optional.Item.Should().NotBeNull();
     Action a = () => Mock.Get(optional);
     a.Should().Throw<ArgumentException>();
 }
 public void Should_return_edit_view_with_person_model_and_error_after_post_to_create_with_duplicate_email()
 {
     _autoMock.Resolve <IPersonRepository>().EmailBelongsToSomeoneElse(_person.EmailAddress).Returns(true);
     _controller.Create(_person).AssertViewRendered().ForView("Edit")
     .WithModel(_person);
     _controller.HasModelError("EmailAddress", "The Email address must be unique; that email address already exists in the system.");
 }
Ejemplo n.º 6
0
        public void Handle_One_Fake_Item()
        {
            var fake1 = AutoMock.Provide(FakeItEasy.A.Fake <Item>());

            var result = AutoMock.Resolve <IEnumerable <Item> >().ToArray();

            result.Should().HaveCount(1);
            result.Should().Contain(fake1);
        }
Ejemplo n.º 7
0
 public void Should_return_edit_view_with_person_model_and_error_after_post_to_create_with_duplicate_email()
 {
     _autoMock.Resolve <IPersonRepository>().EmailBelongsToSomeoneElse(_person.EmailAddress).Returns(true);
     Ensure.That(_controller).Calling(c => c.Create(_person))
     .RendersView("Edit")
     .WithModel(_person)
     .AndModelErrorFor(p => p.EmailAddress).ThatEquals("The Email address must be unique; that email address already exists in the system.");
 }
Ejemplo n.º 8
0
        public void Should_Handle_Creating_A_Mock_With_Logger()
        {
            Action a = () =>
            {
                var lt = AutoMock.Resolve <LoggerTest>();
                AutoMock.Provide <Item>(lt);
            };

            a.Should().NotThrow();
        }
Ejemplo n.º 9
0
        public void Should_return_edit_view_with_person_model_and_error_after_post_to_create_with_duplicate_email()
        {
            // Arrange
            _autoMock.Resolve <IPersonRepository>().EmailBelongsToSomeoneElse(_person.EmailAddress).Returns(true);

            // Act & Assert
            var viewResult = _controller.Create(_person).AssertViewRendered().ForView("Edit");

            Assert.That(viewResult.Model, Is.SameAs(_person), "Model was passed through to view");
            Assert.That(_controller.ModelState["EmailAddress"].Errors[0].ErrorMessage, Is.EqualTo("The Email address must be unique; that email address already exists in the system."), "There is a model state error against the email address field");
        }
 public void Setup()
 {
     _autoMock = new AutoMock();
     _controller = _autoMock.Resolve<PersonController>();
     _person.Id = 0;
 }
Ejemplo n.º 11
0
 public Task <CommitDiff> ParsePatchAsync(CommitSha commitSha, string patch, bool addPrefixes = true) =>
 am.Resolve <IGitDiffParser>().ParseAsync(commitSha, patch, addPrefixes, false);
Ejemplo n.º 12
0
 public void Should_Not_Mock_Optional_Parameters()
 {
     AutoMock.Resolve<Optional>().Item.Should().BeNull();
 }
Ejemplo n.º 13
0
 public void Should_Create_Usable_Logger()
 {
     var test = AutoMock.Resolve<Impl>();
     AutoMock.Mock<ITestOutputHelper>().Verify(x => x.WriteLine(It.IsAny<string>()), Times.AtLeastOnce);
 }
 public void Setup()
 {
     _autoMock   = new AutoMock();
     _controller = _autoMock.Resolve <PersonController>();
     _person.Id  = 0;
 }
Ejemplo n.º 15
0
 public void Handle_Zero_Items()
 {
     AutoMock.Resolve <IEnumerable <Item> >().Should().HaveCount(0);
 }
        public override IEnumerable <ControllerTest <PersonController> > TestSpecifications()
        {
            return(_controller.Describe((callbacks, it) => {
                var autoMock = default(AutoMock);

                callbacks.Before = () =>
                {
                    autoMock = new AutoMock();
                    _controller = autoMock.Resolve <PersonController>();
                    _person.Id = 0;
                };

                it.Should("Render Index view with list of people after get to Index()", () => {
                    _controller.WithCallTo(c => c.Index())
                    .ShouldRenderDefaultView().WithModel <IEnumerable <Person> >();
                });

                it.Should("Render Edit view after get to Create()", () => {
                    _controller.WithCallTo(c => c.Create())
                    .ShouldRenderView("Edit");
                });

                it.Should("Render Edit view with person model after post to Create() with invalid model", () => {
                    _controller.WithModelErrors().WithCallTo(c => c.Create(_person))
                    .ShouldRenderView("Edit").WithModel(_person);
                });

                it.Should("Render Edit view with person model and error after post to Create() with duplicate email", () => {
                    autoMock.Resolve <IPersonRepository>().EmailBelongsToSomeoneElse(_person.EmailAddress).Returns(true);
                    _controller.WithCallTo(c => c.Create(_person))
                    .ShouldRenderView("Edit")
                    .WithModel(_person)
                    .AndModelErrorFor(p => p.EmailAddress).ThatEquals("The Email address must be unique; that email address already exists in the system.");
                });

                it.Should("Save and redirect to Index() after post to Create() with valid person", () => {
                    autoMock.Resolve <IPersonRepository>().EmailBelongsToSomeoneElse(Arg.Any <string>()).Returns(false);
                    _controller.WithCallTo(c => c.Create(_person))
                    .ShouldRedirectTo(c => c.Index);
                    autoMock.Resolve <IPersonRepository>().Received().Save(_person);
                });

                it.Should("Give 404 after get to Edit() with invalid id", () => {
                    _controller.WithCallTo(c => c.Edit(0)).ShouldGiveHttpStatus(404);
                });

                it.Should("Render Edit view with person model after get to Edit() with valid id", () => {
                    autoMock.Resolve <IPersonRepository>().GetById(PersonId).Returns(_person);
                    _controller.WithCallTo(c => c.Edit(PersonId))
                    .ShouldRenderDefaultView().WithModel(_person);
                });

                it.Should("Render Edit view with person model after post to Edit() with invalid model", () => {
                    _controller.WithModelErrors().WithCallTo(c => c.Edit(PersonId, _person))
                    .ShouldRenderDefaultView().WithModel(_person);
                });

                it.Should("Render Edit view with person model and error after post to Edit() with duplicate email", () => {
                    autoMock.Resolve <IPersonRepository>().EmailBelongsToSomeoneElse(_person.EmailAddress, PersonId).Returns(true);
                    _controller.WithCallTo(c => c.Edit(PersonId, _person))
                    .ShouldRenderDefaultView().WithModel(_person)
                    .AndModelErrorFor(p => p.EmailAddress).ThatEquals("The Email address must be unique; that email address already exists in the system.");
                });

                it.Should("Save and redirect to Index() after post to edit with valid person", () => {
                    autoMock.Resolve <IPersonRepository>().EmailBelongsToSomeoneElse(Arg.Any <string>(), Arg.Any <int>()).Returns(false);
                    _controller.WithCallTo(c => c.Edit(PersonId, _person));
                    autoMock.Resolve <IPersonRepository>().Received().Save(_person);
                    Assert.That(_person.Id, Is.EqualTo(PersonId));
                });
            }));
        }