public void SaveScript_Test() { //Arrange var stubFactory = new Mock <IPrompterDbContextFactory>(); var dummyContext = new Mock <IPrompterDbContext>(); stubFactory.Setup(f => f.Create()) .Returns(dummyContext.Object); var dummyScript = new Mock <Script>(); //Act var service = new ScriptService(stubFactory.Object); service.SaveScript(dummyScript.Object); //Assert stubFactory.Verify(f => f.Create(), Times.Exactly(1)); dummyContext.Verify(c => c.Attach(dummyScript.Object) , Times.Exactly(1)); dummyContext.Verify(c => c.SaveChanges() , Times.Exactly(1)); }