public void Get_InputId_CalledFindMethodOfDBSetWithCorrectId()
        {
            // Arrange
            DbContextOptions opt = new DbContextOptionsBuilder <orderContext>()
                                   .Options;
            var mockContext = new Mock <orderContext>(opt);
            var mockDbSet   = new Mock <DbSet <location> >();

            mockContext
            .Setup(context =>
                   context.Set <location>(
                       ))
            .Returns(mockDbSet.Object);

            location expectedStreet = new location()
            {
                id_location = 1
            };

            mockDbSet.Setup(mock => mock.Find(expectedStreet.id_location))
            .Returns(expectedStreet);
            var repository = new TestClientRepository(mockContext.Object);

            //Act
            var actualStreet = repository.Get(expectedStreet.id_location);

            // Assert
            mockDbSet.Verify(
                dbSet => dbSet.Find(
                    expectedStreet.id_location
                    ), Times.Once());
            location.Equals(expectedStreet, actualStreet);
        }
示例#2
0
        public void Get_InputId_CalledFindMethodOfDBSetWithCorrectId()
        {
            // Arrange
            DbContextOptions opt = new DbContextOptionsBuilder <dealContext>()
                                   .Options;
            var mockContext = new Mock <dealContext>(opt);
            var mockDbSet   = new Mock <DbSet <clients> >();

            mockContext
            .Setup(context =>
                   context.Set <clients>(
                       ))
            .Returns(mockDbSet.Object);

            clients expectedStreet = new clients()
            {
                ClientID = 1
            };

            mockDbSet.Setup(mock => mock.Find(expectedStreet.ClientID))
            .Returns(expectedStreet);
            var repository = new TestClientRepository(mockContext.Object);

            //Act
            var actualStreet = repository.Get(expectedStreet.ClientID);

            // Assert
            mockDbSet.Verify(
                dbSet => dbSet.Find(
                    expectedStreet.ClientID
                    ), Times.Once());
            Assert.Equal(expectedStreet, actualStreet);
        }