public void GetHashCode_EqualObjects()
        {
            var handle1 = new DomainObjectHandle <Order> (DomainObjectIDs.Order1);
            var handle2 = new DomainObjectHandle <Order> (DomainObjectIDs.Order1);

            Assert.That(handle1.GetHashCode(), Is.EqualTo(handle2.GetHashCode()));
        }
        public void Equals_Object_True()
        {
            var handle1 = new DomainObjectHandle <Order> (DomainObjectIDs.Order1);
            var handle2 = new DomainObjectHandle <Order> (DomainObjectIDs.Order1);

            Assert.That(handle1.Equals((object)handle2), Is.True);
        }
        public void Equals_Equatable_False_DifferentIDs()
        {
            var handle1 = new DomainObjectHandle <Order> (DomainObjectIDs.Order1);
            var handle2 = new DomainObjectHandle <Order> (DomainObjectIDs.Order2);

            Assert.That(handle1.Equals(handle2), Is.False);
        }
        public void Serializable()
        {
            var handle = new DomainObjectHandle <Order> (DomainObjectIDs.Order1);

            var result = Serializer.SerializeAndDeserialize(handle);

            Assert.That(result, Is.EqualTo(handle));
        }
        public void Equals_Equatable_False_Null()
        {
            var handle = new DomainObjectHandle <Order> (DomainObjectIDs.Order1);

// ReSharper disable RedundantCast
            Assert.That(handle.Equals((IDomainObjectHandle <DomainObject>)null), Is.False);
// ReSharper restore RedundantCast
        }
        public void Cast_CanDowncast()
        {
            var handle = new DomainObjectHandle <Order> (DomainObjectIDs.Order1).Cast <DomainObject> ();

            var result = handle.Cast <Order>();

            Assert.That(result, Is.SameAs(handle));
            Assert.That(VariableTypeInferrer.GetVariableType(result), Is.SameAs(typeof(IDomainObjectHandle <Order>)));
        }
        public void Equals_Equatable_False_WrongType()
        {
            var handle1 = new DomainObjectHandle <Order> (DomainObjectIDs.Order1);
            var handle2 = MockRepository.GenerateStub <IDomainObjectHandle <DomainObject> > ();

            handle2.Stub(stub => stub.ObjectID).Return(DomainObjectIDs.Order1);

            Assert.That(handle1.Equals(handle2), Is.False);
        }
        public void Cast_ThrowsOnUnsupportedCast()
        {
            var handle = new DomainObjectHandle <Order> (DomainObjectIDs.Order1);

            Assert.That(
                () => handle.Cast <OrderItem> (),
                Throws.TypeOf <InvalidCastException> ().With.Message.EqualTo(
                    "The handle for object 'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid' cannot be represented as a handle for type "
                    + "'Remotion.Data.DomainObjects.UnitTests.TestDomain.OrderItem'."));
        }
        public void Equals_Object_False_Null()
        {
            var handle = new DomainObjectHandle <Order> (DomainObjectIDs.Order1);

            Assert.That(handle.Equals((object)null), Is.False);
        }
        public void Initialization()
        {
            var handle = new DomainObjectHandle <Order> (DomainObjectIDs.Order1);

            Assert.That(handle.ObjectID, Is.EqualTo(DomainObjectIDs.Order1));
        }
        public new void ToString()
        {
            var handle = new DomainObjectHandle <Order> (DomainObjectIDs.Order1);

            Assert.That(handle.ToString(), Is.EqualTo("Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid (handle)"));
        }
        public void Equals_Object_False_UnrelatedObject()
        {
            var handle = new DomainObjectHandle <Order> (DomainObjectIDs.Order1);

            Assert.That(handle.Equals("what?"), Is.False);
        }