Ejemplo n.º 1
0
    public void Test_Display_Nonexistant_Parameter()
    {
        //Arrange
        var Photos = new[] {
            new Photo {
                PhotoID = 1, Title = "Photo1"
            },
            new Photo {
                PhotoID = 2, Title = "Photo2"
            },
            new Photo {
                PhotoID = 3, Title = "Photo3"
            },
            new Photo {
                PhotoID = 4, Title = "Photo4"
            }
        }.AsQueryable();
        var contextMock = new Mock <IPhotoSharingContext>();

        contextMock.Setup(x => x.FindPhotoById(1)).Returns(Photos.ToArray()[0]);
        contextMock.Setup(x => x.FindPhotoById(2)).Returns(Photos.ToArray()[1]);
        contextMock.Setup(x => x.FindPhotoById(3)).Returns(Photos.ToArray()[2]);
        contextMock.Setup(x => x.FindPhotoById(4)).Returns(Photos.ToArray()[3]);
        var controller = new PhotoController(contextMock.Object);
        var result     = controller.Display(5);

        Assert.AreEqual(typeof(HttpNotFoundResult), result.GetType());
    }
    public void Test_Display_Int_Parameter()
    {
        context.Photos = new[] {
            new Photo {
                PhotoID = 1, Title = "Photo1"
            },
            new Photo {
                PhotoID = 2, Title = "Photo2"
            },
            new Photo {
                PhotoID = 3, Title = "Photo3"
            },
            new Photo {
                PhotoID = 4, Title = "Photo4"
            }
        }.AsQueryable();
        var result      = controller.Display(2) as ViewResult;
        var resultPhoto = (Photo)result.Model;

        Assert.AreEqual("Photo2", resultPhoto.Title);
    }
Ejemplo n.º 3
0
    public void Test_Display_Nonexistant_Parameter_Empty_Photos()
    {
        //Arrange
        var contextMock = new Mock <IPhotoSharingContext>();

        contextMock.Setup(x => x.FindPhotoById(It.IsAny <int>())).Returns((Photo)null);
        var controller = new PhotoController(contextMock.Object);
        //Act
        var result = controller.Display(5);

        //Assert
        Assert.AreEqual(typeof(HttpNotFoundResult), result.GetType());
    }