public override bool Equals(object obj)
        {
            System.Diagnostics.Debug.WriteLine("Equals obj");

            if (ReferenceEquals(this, NOT_AVAILABLE))
            {
                return(false);
            }
            if (ReferenceEquals(obj, NOT_AVAILABLE))
            {
                return(false);
            }

            if (ReferenceEquals(this, obj))
            {
                return(true);
            }

            ConditionalGetFingerprint conditionalGetFingerprint = obj as ConditionalGetFingerprint;

            if (conditionalGetFingerprint == null)
            {
                return(false);
            }

            return
                (lastModifiedTime.Equals(conditionalGetFingerprint.lastModifiedTime) &&
                 eTag.Equals(conditionalGetFingerprint.eTag));
        }
        public void NotAvailableShouldAlwaysProduceNotAvailableWhenCombined()
        {
            ConditionalGetFingerprint testFingerprint = new ConditionalGetFingerprint(testDate, testETag);

            Assert.AreSame(ConditionalGetFingerprint.NOT_AVAILABLE, ConditionalGetFingerprint.NOT_AVAILABLE.Combine(testFingerprint));
            Assert.AreSame(ConditionalGetFingerprint.NOT_AVAILABLE, testFingerprint.Combine(ConditionalGetFingerprint.NOT_AVAILABLE));
        }
        public void ShouldThrowExceptionIfFingerprintsAreCombinedWhichHaveDifferentETags()
        {
            ConditionalGetFingerprint testFingerprint = new ConditionalGetFingerprint(testDate, testETag);
            ConditionalGetFingerprint fingerprintWithDifferentETag= new ConditionalGetFingerprint(testDate, testETag + "different");

            Assert.That(delegate { testFingerprint.Combine(fingerprintWithDifferentETag); },
                        Throws.TypeOf<UncombinableFingerprintException>());
        }
        public void ShouldBeEqualIfDateAndETagAreEqual()
        {
            ConditionalGetFingerprint firstFingerprint = new ConditionalGetFingerprint(testDate, testETag);
            ConditionalGetFingerprint secondFingerprint = new ConditionalGetFingerprint(testDate, testETag);

            Assert.AreEqual(firstFingerprint, secondFingerprint);
            Assert.AreNotSame(firstFingerprint, secondFingerprint);
        }
        public ConditionalGetFingerprint Combine(ConditionalGetFingerprint other)
        {
            if (this == NOT_AVAILABLE || other == NOT_AVAILABLE) return NOT_AVAILABLE;
            if (eTag != other.eTag) throw new UncombinableFingerprintException(eTag, other.eTag);

            DateTime newerModificationTime = DateUtil.MaxDate(lastModifiedTime, other.lastModifiedTime);
            return new ConditionalGetFingerprint(newerModificationTime, eTag);
        }
        public void ShouldNotBeEqualIfDatesDiffer()
        {
            ConditionalGetFingerprint firstFingerprint = new ConditionalGetFingerprint(testDate, testETag);

			DateTime differentDate = new DateTime(2007, 3, 22, 22, 50, 29, DateTimeKind.Utc);
			ConditionalGetFingerprint secondFingerprint = new ConditionalGetFingerprint(differentDate, testETag);

            Assert.AreNotEqual(firstFingerprint, secondFingerprint);
        }
        public void ShouldUseMostRecentDateWhenCombined()
        {
            DateTime olderDate = new DateTime(2006,12,1);
            DateTime recentDate = new DateTime(2007,2,1);

            ConditionalGetFingerprint olderFingerprint = new ConditionalGetFingerprint(olderDate, testETag);
            ConditionalGetFingerprint newerFingerprint = new ConditionalGetFingerprint(recentDate, testETag);

            ConditionalGetFingerprint expectedFingerprint = newerFingerprint;
            Assert.AreEqual(expectedFingerprint, olderFingerprint.Combine(newerFingerprint));
        }
        public ConditionalGetFingerprint Combine(ConditionalGetFingerprint other)
        {
            if (this == NOT_AVAILABLE || other == NOT_AVAILABLE)
            {
                return(NOT_AVAILABLE);
            }
            if (eTag != other.eTag)
            {
                throw new UncombinableFingerprintException(eTag, other.eTag);
            }

            DateTime newerModificationTime = DateUtil.MaxDate(lastModifiedTime, other.lastModifiedTime);

            return(new ConditionalGetFingerprint(newerModificationTime, eTag));
        }
        public override bool Equals(object obj)
        {
            if (this == NOT_AVAILABLE || obj == NOT_AVAILABLE)
            {
                return(false);
            }
            if (this == obj)
            {
                return(true);
            }
            ConditionalGetFingerprint conditionalGetFingerprint = obj as ConditionalGetFingerprint;

            if (conditionalGetFingerprint == null)
            {
                return(false);
            }

            return
                (lastModifiedTime.Equals(conditionalGetFingerprint.lastModifiedTime) &&
                 eTag.Equals(conditionalGetFingerprint.eTag));
        }
	    public void ShouldReturnNotModifiedResponseIfClientFingerprintMatchesServerFingerprint()
	    {
            ConditionalGetFingerprint sharedFingerprint = new ConditionalGetFingerprint(new DateTime(1980, 10, 30), "None-Match-String");

            mockActionFactory.ExpectAndReturn("CreateFingerprintProvider", fingerprintableContentProvider, request);
            mockFingerprintFactory.ExpectAndReturn("BuildFromRequest", sharedFingerprint, request);
            mockActionFactory.ExpectAndReturn("Create", action, request);

            mockAction.ExpectAndReturn("Execute", response, request);
            mockFingerprintableContentProvider.ExpectAndReturn("GetFingerprint", sharedFingerprint, request);

            IResponse actualResponse = controller.Do();

            Assert.IsAssignableFrom(typeof(NotModifiedResponse), actualResponse);
            Assert.AreEqual(sharedFingerprint, actualResponse.ServerFingerprint);
	    }
        public void ShouldReturnNormalResponseWithServerProvidedFingerprintIfClientDidNotProvideFingerprint()
        {
            mockActionFactory.ExpectAndReturn("CreateFingerprintProvider", fingerprintableContentProvider, request);
            mockFingerprintFactory.ExpectAndReturn("BuildFromRequest", ConditionalGetFingerprint.NOT_AVAILABLE, request);
            mockActionFactory.ExpectAndReturn("Create", action, request);

            mockAction.ExpectAndReturn("Execute", response, request);
            ConditionalGetFingerprint fingerprint = new ConditionalGetFingerprint(DateTime.Now, "test token");
            mockFingerprintableContentProvider.ExpectAndReturn("GetFingerprint", fingerprint, request);

            IResponse actualResponse = controller.Do();

            Assert.IsAssignableFrom(typeof(HtmlFragmentResponse), actualResponse);
            Assert.AreEqual(fingerprint, actualResponse.ServerFingerprint);
        }
        public void ShouldNeverEqualNotAvailable()
        {
            ConditionalGetFingerprint testFingerprint = new ConditionalGetFingerprint(testDate, testETag);

            Assert.AreNotEqual(testFingerprint, ConditionalGetFingerprint.NOT_AVAILABLE);
        }
	    public void ShouldReturnFingerprintBasedOnLogFileDateAndTemplateDate()
	    {
	        const string TEST_TOKEN = "test token";
            DateTime logFileDate = new DateTime(2006,12,2,1,4,5);
            DateTime templateDate = new DateTime(2005,1,2);

            DynamicMock requestMock = new DynamicMock(typeof(IRequest));
            requestMock.SetupResult("SubFolders", new string[] { "server", "testServer", "project", "testProject", "build", "testBuild" });

	        ConditionalGetFingerprint expectedFingerprint = new ConditionalGetFingerprint(logFileDate, TEST_TOKEN);

            Assert.AreEqual(expectedFingerprint, buildLogAction.GetFingerprint((IRequest) requestMock.MockInstance));
	    }
	    public void ShouldReturnFingerprintBasedOnLatestBuildDateAndVelocityTemplates()
	    {
            // TODO: Had to change content of build2specifier so that lister.GetFingerprint could new LogFile().Date
            // Would be nice to have a cleaner way of getting the date. Possibly from the specifier directly?
            const string testToken = "test token";

            DynamicMock requestMock = new DynamicMock(typeof(IRequest));
	        IRequest request = (IRequest) requestMock.MockInstance;

            DateTime olderDate = new DateTime(2007,1,1,1,1,1);
            DateTime mostRecentDate = new DateTime(2007, 4, 21, 1, 7, 8);

	        fingerprintFactoryMock.SetupResult("BuildFromDate", new ConditionalGetFingerprint(olderDate, testToken), typeof(DateTime));
            fingerprintFactoryMock.SetupResult("BuildFromFileNames", new ConditionalGetFingerprint(mostRecentDate, testToken), typeof(string[]));

            requestMock.SetupResult("SubFolders", new string[] {"server", "testServer", "project", "testProject", "build", "testBuild"});

            farmServiceMock.SetupResult("GetMostRecentBuildSpecifiers", new IBuildSpecifier[] { build2Specifier, build1Specifier }, typeof(IProjectSpecifier), typeof(int), null);

	        ConditionalGetFingerprint expectedFingerprint = new ConditionalGetFingerprint(mostRecentDate, testToken);

            Assert.AreEqual(expectedFingerprint, lister.GetFingerprint(request));
	    }
 public NotModifiedResponse(ConditionalGetFingerprint serverFingerprint)
 {
     this.serverFingerprint = serverFingerprint;
 }