예제 #1
0
    public void GenerateData_SatisfiesDisposablePattern()
    {
        FinancialService service = new FinancialService();
        var repo = DisposablePattern.For(new Mock <IRepository <FinancialTarget> >().Object);

        service.GenerateData(() => repo.Object);

        repo.VerifyDisposed();
    }
예제 #2
0
        public void GenerateDataOfRepoFactory_SaveCalled()
        {
            var repo = new Mock <IRepository <FinancialTarget> >();
            FinancialService service = new FinancialService(repo.Object);

            service.GenerateData(() => repo.Object);

            repo.Verify(r => r.Save(), Times.AtLeastOnce());
        }
        public void GenerateDataParameterless_DoesNotCallDispose()
        {
            var repo = new Mock <IRepository <FinancialTarget> >();
            FinancialService service = new FinancialService(repo.Object);

            service.GenerateData();

            repo.Verify(x => x.Dispose(), Times.Never);
        }
예제 #4
0
    public void GenerateData_CallsDispose()
    {
        FinancialService service = new FinancialService();

        var repo = new Mock <IRepository <FinancialTarget> >();

        service.GenerateData(() => repo.Object);

        repo.Verify(x => x.Dispose(), Times.AtLeastOnce);
    }
예제 #5
0
        public void GenerateDataOfRepoFactory_AddsNothingAfterSave()
        {
            var repo = new Mock <IRepository <FinancialTarget> >();

            bool saveCalled         = false;
            bool addCalledAfterSave = false;

            repo.Setup(r => r.Save()).Callback(() => saveCalled = true);
            repo.Setup(r => r.Add(It.IsAny <FinancialTarget>())).Callback(() => addCalledAfterSave = saveCalled);

            FinancialService service = new FinancialService(repo.Object);

            service.GenerateData(() => repo.Object);

            Assert.False(addCalledAfterSave);
        }