public void ChangeStateOf_Stateful_WhenCalledWithValidParameters() { // Arange var mockedStaful = new Mock <IStateful <IDbModel> >(); mockedStaful.SetupSet(x => x.State = EntityState.Modified).Verifiable(); var fakeDbSet = new Mock <DbSet <IDbModel> >(); var fakeDbModel = new Mock <IDbModel>(); var mockDbContext = new Mock <IWhenItsDoneDbContext>(); mockDbContext.Setup(mock => mock.Set <IDbModel>()).Returns(fakeDbSet.Object); mockDbContext.Setup(mock => mock.GetStateful(It.IsAny <IDbModel>())).Returns(mockedStaful.Object); var asyncGenericRepositoryInstace = new GenericAsyncRepository <IDbModel>(mockDbContext.Object); // Act asyncGenericRepositoryInstace.Update(fakeDbModel.Object); // Assert mockedStaful.Verify(); }
public void ThrowArgumentNullExceptionWithCorrectMessage_WhenEntityParameterIsNull() { // Arange IDbModel entity = null; var fakeDbSet = new Mock <DbSet <IDbModel> >(); var mockDbContext = new Mock <IWhenItsDoneDbContext>(); mockDbContext.Setup(mock => mock.Set <IDbModel>()).Returns(fakeDbSet.Object); var asyncGenericRepositoryInstace = new GenericAsyncRepository <IDbModel>(mockDbContext.Object); // Act & Assert Assert.That( () => asyncGenericRepositoryInstace.Update(entity), Throws.InstanceOf <ArgumentNullException>().With.Message.Contains(nameof(entity))); }
public void InvokeDbContextEntryMethodWithCorrectParameter_WhenParametersAreValid() { // Arange var mockedStaful = new Mock <IStateful <IDbModel> >(); var fakeDbSet = new Mock <DbSet <IDbModel> >(); var fakeDbModel = new Mock <IDbModel>(); var mockDbContext = new Mock <IWhenItsDoneDbContext>(); mockDbContext.Setup(mock => mock.Set <IDbModel>()).Returns(fakeDbSet.Object); mockDbContext.Setup(mock => mock.GetStateful(It.IsAny <IDbModel>())).Returns(mockedStaful.Object); var asyncGenericRepositoryInstace = new GenericAsyncRepository <IDbModel>(mockDbContext.Object); // Act asyncGenericRepositoryInstace.Update(fakeDbModel.Object); // Assert mockDbContext.Verify(mock => mock.GetStateful(fakeDbModel.Object), Times.Once()); }