public void Image_WithCode_ReturnsResultWithCorrectCodeAndContentTypeAndDefaultSize()
        {
            // arrange
            var controller = new IdenticonController();

            // act
            var result = controller.Image(123) as IdenticonResult;

            // assert
            Assert.AreEqual(123, result.Code);
            Assert.AreEqual(40, result.Size);
            Assert.AreEqual("image/png", result.ContentType);
        }
        public void Image_WithoutCode_ReturnsCodeBasedOnIpAddress()
        {
            // arrange
            var controller = new IdenticonController();
            var controllerContext = new Mock<ControllerContext>();
            controller.ControllerContext = controllerContext.Object;
            controllerContext.Setup(c => c.HttpContext.Request.UserHostAddress).Returns("123.234.245.255");

            // act
            var result = controller.Image(null) as IdenticonResult;

            // assert
            Assert.AreEqual(-315619697, result.Code);
        }
        public void Image_WithRequestMatchingEtag_ReturnsNotModifiedResult()
        {
            // arrange
            string etag = IdenticonUtil.ETag(-1234, 40);
            var controller = new IdenticonController();
            var controllerContext = new Mock<ControllerContext>();
            controller.ControllerContext = controllerContext.Object;
            controllerContext.Setup(c => c.HttpContext.Request.Headers).Returns(new NameValueCollection {{"If-None-Match", etag}});

            // act
            var result = controller.Image(-1234) as NotModifiedResult;

            // assert
            Assert.IsNotNull(result);
        }
        public void Image_WithSize_ReturnsResultWithSpecifiedSize()
        {
            // arrange
            var controller = new IdenticonController(new NameValueCollection{{"IdenticonSize", "80"}});

            // act
            var result = controller.Image(0) as IdenticonResult;

            // assert
            Assert.AreEqual(80, result.Size);
        }