예제 #1
0
        public void Save_UpdatedEntryValues_ReturnsUpdatedDataSet()
        {
            // Arrange
            var dataSource  = GetEntriesData();
            var mockSet     = new MockDbSet <Entry>(dataSource);
            var mockContext = new Mock <GlossaryContext>();

            mockContext.Setup(c => c.Set <Entry>()).Returns(mockSet.Object);

            var controller = new EntryController(mockContext.Object);

            Entry updatedEntry = new Entry()
            {
                Id         = dataSource.First().Id,
                Term       = dataSource.First().Term,
                Definition = dataSource.First().Definition
            };

            updatedEntry.Term       = "New Term Value From User";
            updatedEntry.Definition = "New Defintion Text to Replace Defintion From User Input";

            // Act
            controller.Save(updatedEntry);

            // Assert
            Assert.AreEqual(dataSource.First().Term, updatedEntry.Term);
            Assert.AreEqual(dataSource.First().Definition, updatedEntry.Definition);
        }
예제 #2
0
        public void Save_UpdatedEntryValuesForInvalidEntry_ThrowsHttpException()
        {
            // Arrange
            var dataSource  = GetEntriesData();
            var mockSet     = new MockDbSet <Entry>(dataSource);
            var mockContext = new Mock <GlossaryContext>();

            mockContext.Setup(c => c.Set <Entry>()).Returns(mockSet.Object);

            var controller = new EntryController(mockContext.Object);

            Entry updatedEntry = new Entry()
            {
                Id         = 9999,
                Term       = dataSource.First().Term,
                Definition = dataSource.First().Definition
            };

            // Assert
            Assert.ThrowsException <HttpException>(() => controller.Save(updatedEntry));
        }