Exemplo n.º 1
0
        public void Equals_07()
        {
            // arrange:
            UnLocode  dpLocode         = new UnLocode("DPLOC");
            UnLocode  arLocode         = new UnLocode("ARLOC");
            ILocation targetDpLocation = MockRepository.GenerateStrictMock <ILocation>();
            ILocation targetArLocation = MockRepository.GenerateStrictMock <ILocation>();

            targetDpLocation.Expect(l => l.UnLocode).Return(dpLocode).Repeat.AtLeastOnce();
            targetArLocation.Expect(l => l.UnLocode).Return(arLocode).Repeat.AtLeastOnce();
            DateTime dpTime = DateTime.UtcNow - new TimeSpan(48, 0, 0);
            DateTime arTime = DateTime.UtcNow + new TimeSpan(48, 0, 0);

            // act:
            ICarrierMovement target1 = new CarrierMovement(targetDpLocation, dpTime, targetArLocation, arTime);
            ICarrierMovement target2 = new CarrierMovement(targetDpLocation, dpTime, targetArLocation, arTime);

            // assert:
            Assert.IsTrue(target1.Equals(target2));
            Assert.IsTrue(target2.Equals(target1));
            Assert.IsTrue(target1.Equals((object)target2));
            Assert.IsTrue(target2.Equals((object)target1));
            Assert.AreEqual(target1.GetHashCode(), target2.GetHashCode());
            targetDpLocation.VerifyAllExpectations();
            targetArLocation.VerifyAllExpectations();
        }
Exemplo n.º 2
0
        public void Equals_01()
        {
            // arrange:
            UnLocode  dpLocode         = new UnLocode("DPLOC");
            UnLocode  arLocode         = new UnLocode("ARLOC");
            ILocation targetDpLocation = MockRepository.GenerateStrictMock <ILocation>();
            ILocation targetArLocation = MockRepository.GenerateStrictMock <ILocation>();

            targetDpLocation.Expect(l => l.UnLocode).Return(dpLocode).Repeat.AtLeastOnce();
            targetArLocation.Expect(l => l.UnLocode).Return(arLocode).Repeat.AtLeastOnce();
            DateTime dpTime = DateTime.UtcNow - new TimeSpan(48, 0, 0);
            DateTime arTime = DateTime.UtcNow + new TimeSpan(48, 0, 0);

            ICarrierMovement mock = MockRepository.GenerateStrictMock <ICarrierMovement>();

            mock.Expect(m => m.DepartureLocation).Return(dpLocode).Repeat.AtLeastOnce();
            mock.Expect(m => m.ArrivalLocation).Return(arLocode).Repeat.AtLeastOnce();
            mock.Expect(m => m.ArrivalTime).Return(arTime).Repeat.Once();
            mock.Expect(m => m.DepartureTime).Return(dpTime).Repeat.Once();


            // act:
            ICarrierMovement target    = new CarrierMovement(targetDpLocation, dpTime, targetArLocation, arTime);
            bool             areEquals = target.Equals(mock);

            // assert:
            Assert.IsTrue(areEquals);
            Assert.IsTrue(target.Equals(target));
            Assert.IsFalse(target.Equals(null));
            targetDpLocation.VerifyAllExpectations();
            targetArLocation.VerifyAllExpectations();
            mock.VerifyAllExpectations();
        }
        public void TestSameValueAsEqualsHashCode()
        {
            var cm1 = new CarrierMovement(SampleLocations.STOCKHOLM, SampleLocations.HAMBURG, new DateTime(), new DateTime());
            var cm2 = new CarrierMovement(SampleLocations.STOCKHOLM, SampleLocations.HAMBURG, new DateTime(), new DateTime());
            var cm3 = new CarrierMovement(SampleLocations.HAMBURG, SampleLocations.STOCKHOLM, new DateTime(), new DateTime());
            var cm4 = new CarrierMovement(SampleLocations.HAMBURG, SampleLocations.STOCKHOLM, new DateTime(), new DateTime());            

            Assert.IsTrue(cm1.SameValueAs(cm2));
            Assert.IsFalse(cm2.SameValueAs(cm3));
            Assert.IsTrue(cm3.SameValueAs(cm4));

            Assert.IsTrue(cm1.Equals(cm2));
            Assert.IsFalse(cm2.Equals(cm3));
            Assert.IsTrue(cm3.Equals(cm4));

            Assert.IsTrue(cm1.GetHashCode() == cm2.GetHashCode());
            Assert.IsFalse(cm2.GetHashCode() == cm3.GetHashCode());
            Assert.IsTrue(cm3.GetHashCode() == cm4.GetHashCode());
        }
Exemplo n.º 4
0
        public void TestSameValueAsEqualsHashCode()
        {
            var cm1 = new CarrierMovement(SampleLocations.STOCKHOLM, SampleLocations.HAMBURG, new DateTime(), new DateTime());
            var cm2 = new CarrierMovement(SampleLocations.STOCKHOLM, SampleLocations.HAMBURG, new DateTime(), new DateTime());
            var cm3 = new CarrierMovement(SampleLocations.HAMBURG, SampleLocations.STOCKHOLM, new DateTime(), new DateTime());
            var cm4 = new CarrierMovement(SampleLocations.HAMBURG, SampleLocations.STOCKHOLM, new DateTime(), new DateTime());

            Assert.IsTrue(cm1.SameValueAs(cm2));
            Assert.IsFalse(cm2.SameValueAs(cm3));
            Assert.IsTrue(cm3.SameValueAs(cm4));

            Assert.IsTrue(cm1.Equals(cm2));
            Assert.IsFalse(cm2.Equals(cm3));
            Assert.IsTrue(cm3.Equals(cm4));

            Assert.IsTrue(cm1.GetHashCode() == cm2.GetHashCode());
            Assert.IsFalse(cm2.GetHashCode() == cm3.GetHashCode());
            Assert.IsTrue(cm3.GetHashCode() == cm4.GetHashCode());
        }
Exemplo n.º 5
0
        public void testSameValueAsEqualsHashCode()
        {
            CarrierMovement cm1 = new CarrierMovement(L.STOCKHOLM, L.HAMBURG, new DateTime(1), new DateTime(2));
            CarrierMovement cm2 = new CarrierMovement(L.STOCKHOLM, L.HAMBURG, new DateTime(1), new DateTime(2));
            CarrierMovement cm3 = new CarrierMovement(L.HAMBURG, L.STOCKHOLM, new DateTime(1), new DateTime(2));
            CarrierMovement cm4 = new CarrierMovement(L.HAMBURG, L.STOCKHOLM, new DateTime(1), new DateTime(2));

            Assert.True(cm1.sameValueAs(cm2));
            Assert.False(cm2.sameValueAs(cm3));
            Assert.True(cm3.sameValueAs(cm4));

            Assert.True(cm1.Equals(cm2));
            Assert.False(cm2.Equals(cm3));
            Assert.True(cm3.Equals(cm4));

            Assert.True(cm1.GetHashCode() == cm2.GetHashCode());
            Assert.False(cm2.GetHashCode() == cm3.GetHashCode());
            Assert.True(cm3.GetHashCode() == cm4.GetHashCode());
        }
Exemplo n.º 6
0
        public void testSameValueAsEqualsHashCode()
        {
            CarrierMovement cm1 = new CarrierMovement(L.STOCKHOLM, L.HAMBURG, new DateTime(1), new DateTime(2));
            CarrierMovement cm2 = new CarrierMovement(L.STOCKHOLM, L.HAMBURG, new DateTime(1), new DateTime(2));
            CarrierMovement cm3 = new CarrierMovement(L.HAMBURG, L.STOCKHOLM, new DateTime(1), new DateTime(2));
            CarrierMovement cm4 = new CarrierMovement(L.HAMBURG, L.STOCKHOLM, new DateTime(1), new DateTime(2));

            Assert.True(cm1.sameValueAs(cm2));
            Assert.False(cm2.sameValueAs(cm3));
            Assert.True(cm3.sameValueAs(cm4));

            Assert.True(cm1.Equals(cm2));
            Assert.False(cm2.Equals(cm3));
            Assert.True(cm3.Equals(cm4));

            Assert.True(cm1.GetHashCode() == cm2.GetHashCode());
            Assert.False(cm2.GetHashCode() == cm3.GetHashCode());
            Assert.True(cm3.GetHashCode() == cm4.GetHashCode());
        }