Beispiel #1
0
        public void ChangeStateOf_Stateful_WhenCalledWithValidParameters()
        {
            // Arange
            var mockedStaful = new Mock <IStateful <IDbModel> >();

            mockedStaful.SetupSet(x => x.State = EntityState.Added).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.Add(fakeDbModel.Object);

            // Assert
            mockedStaful.Verify();
        }
Beispiel #2
0
        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.Add(entity),
                Throws.InstanceOf <ArgumentNullException>().With.Message.Contains(nameof(entity)));
        }
Beispiel #3
0
        public void InvokeDbContextGetStatefulMethodWithCorrectParameter_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.Add(fakeDbModel.Object);

            // Assert
            mockDbContext.Verify(mock => mock.GetStateful(fakeDbModel.Object), Times.Once());
        }