Пример #1
0
 private static List <CompanyView> BuildCompanyViewList()
 {
     return(new List <CompanyView>()
     {
         ViewFixture.BuildCompanyView("test")
     });
 }
Пример #2
0
        public void TestUpdateThrowsException()
        {
            DbContextMock.Setup(context => context.Companies)
            .Throws(new Exception("test exception"));

            var view = ViewFixture.BuildCompanyView("test");

            var result = _companyService.Update(view);

            result.ShouldBeLeft(left => left.Should().Be("can't update company"));

            DbContextMock.Verify(context => context.Companies);
        }
Пример #3
0
        public void TestUpdateNonExistingCompany()
        {
            DbContextMock.Setup(context => context.Companies)
            .ReturnsDbSet(new List <Company>());

            var view = ViewFixture.BuildCompanyView("test");

            var result = _companyService.Update(view);

            result.ShouldBeLeft(left => left.Should().Be("company not found"));

            DbContextMock.Verify(context => context.Companies);
        }
Пример #4
0
        public void TestAddExistingCompany()
        {
            DbContextMock.Setup(context => context.Companies)
            .ReturnsDbSet(BuildCompanyList());

            var view = ViewFixture.BuildCompanyView("test");

            var result = _companyService.Add(view);

            result.ShouldBeLeft(left => left.Should().Be("company already exists"));

            DbContextMock.Verify(context => context.Companies);
        }
Пример #5
0
        public void TestGetCompany()
        {
            const long id      = 1;
            var        company = DataFixture.BuildCompany("test");
            var        view    = ViewFixture.BuildCompanyView("test");

            DbContextMock.Setup(context => context.Companies.Find(It.IsAny <long>()))
            .Returns(company);

            var result = _companyService.Get(id);

            result.ShouldBeRight(right => right.Should().BeEquivalentTo(view));

            DbContextMock.Verify(context => context.Companies);
        }
Пример #6
0
        public void TestAddCompany()
        {
            DbContextMock.Setup(context => context.Companies)
            .ReturnsDbSet(new List <Company>());

            var view = ViewFixture.BuildCompanyView("test");

            var result = _companyService.Add(view);

            result.ShouldBeRight(right => right.Should().BeEquivalentTo(view));

            DbContextMock.Verify(context => context.Companies);
            DbContextMock.Verify(context => context.Companies.Add(It.IsAny <Company>()));
            DbContextMock.Verify(context => context.SaveChanges());
        }
Пример #7
0
        public void TestUpdate()
        {
            var company = DataFixture.BuildCompany("test");
            var view    = ViewFixture.BuildCompanyView("test");

            DbContextMock.Setup(context => context.Companies.Find(view.Id))
            .Returns(company);

            var result = _companyService.Update(view);

            result.ShouldBeRight(right => right.Should().BeEquivalentTo(view));

            DbContextMock.Verify(context => context.Companies);
            DbContextMock.Verify(context => context.Companies.Update(company));
            DbContextMock.Verify(context => context.SaveChanges());
        }