コード例 #1
0
        public void AssociateOriginal_ChangeSet_GetOriginal()
        {
            var proxy = DomainServiceProxy.Create <IMockDomainServiceContract, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Submit));

            Assert.IsNull(this.OperationInvokedArgs);

            var entity = proxy.GetSingletonEntity();

            entity.Name = "CurrentEntity";
            Assert.AreEqual("CurrentEntity", entity.Name);

            var original = new MockEntity()
            {
                ID = entity.ID, Name = "OriginalEntity"
            };

            DomainServiceProxy.AssociateOriginal(proxy, entity, original);

            proxy.UpdateEntity(entity);
            Assert.IsNotNull(this.OperationInvokedArgs);
            Assert.AreEqual("UpdateEntity", this.OperationInvokedArgs.Name);
            Assert.AreEqual(1, this.OperationInvokedArgs.Parameters.Count);
            Assert.AreSame(entity, this.OperationInvokedArgs.Parameters.Values.Single());
            Assert.AreEqual("OriginalEntity", entity.Name);
        }
コード例 #2
0
        public void DisposalTracking()
        {
            var proxy  = DomainServiceProxy.Create <IMockDomainServiceContract, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Submit));
            var entity = new MockEntity();

            var args = new List <OperationInvokedEventArgs>();
            EventHandler <OperationInvokedEventArgs> handler = (s, a) => args.Add(a);

            try
            {
                MockDomainService.Disposed += handler;

                // Invoke a operation multiple times
                proxy.CustomMethod(entity);
                proxy.CustomMethod(entity);
                proxy.CustomMethod(entity);

                proxy.Dispose();

                Assert.AreEqual(3, args.Count);
                Assert.AreEqual("Dispose", args[0].Name);
                Assert.AreEqual("Dispose", args[1].Name);
                Assert.AreEqual("Dispose", args[2].Name);
            }
            finally
            {
                MockDomainService.Disposed -= handler;
            }
        }
コード例 #3
0
 public void Create_InvalidContract_ParameterMismatch()
 {
     ExceptionHelper.ExpectInvalidOperationException(
         () => DomainServiceProxy.Create <IMockDomainServiceContract_InvalidParameters, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Query)),
         string.Format(
             CultureInfo.CurrentCulture,
             Resource.DomainServiceProxyGenerator_OperationMismatch,
             typeof(IMockDomainServiceContract_InvalidParameters),
             "GetEntities"));
 }
コード例 #4
0
 public void Create_InvalidContract_Overloads()
 {
     ExceptionHelper.ExpectInvalidOperationException(
         () => DomainServiceProxy.Create <IMockDomainServiceContract_InvalidOverrides, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Query)),
         string.Format(
             CultureInfo.CurrentCulture,
             Resource.DomainServiceProxyGenerator_OverridesNotSupported,
             typeof(IMockDomainServiceContract_InvalidOverrides),
             "GetEntities"));
 }
コード例 #5
0
 public void Create_InvalidDomainServiceAccessibility()
 {
     ExceptionHelper.ExpectArgumentException(
         () => DomainServiceProxy.Create <IMockDomainServiceContract_ValidAccessibility, MockDomainService_InvalidAccessibility>(new MockDomainServiceContext(DomainOperationType.Query)),
         string.Format(
             CultureInfo.CurrentCulture,
             Resource.DomainServiceProxyGenerator_ExpectedPublicType,
             typeof(MockDomainService_InvalidAccessibility)),
         "domainService");
 }
コード例 #6
0
 public void Create_InvalidContractEvents()
 {
     ExceptionHelper.ExpectInvalidOperationException(
         () => DomainServiceProxy.Create <IMockDomainServiceContract_InvalidEvents, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Query)),
         string.Format(
             CultureInfo.CurrentCulture,
             Resource.DomainServiceProxyGenerator_MethodCountMismatch,
             typeof(IMockDomainServiceContract_InvalidEvents),
             typeof(MockDomainService),
             "add_InvalidEvent, remove_InvalidEvent"));
 }
コード例 #7
0
        public void Query_ContinuableOperationError()
        {
            var proxy = DomainServiceProxy.Create <IMockDomainServiceContract, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Query));

            Assert.IsNull(this.OperationInvokedArgs);


            var ex = ExceptionHelper.ExpectException <OperationException>(
                () => proxy.GetEntitiesWithParams("abc", 499, 501, new Uri("http://param4", UriKind.Absolute)),
                Resource.DomainServiceProxy_OperationError);

            Assert.AreEqual(1, ex.OperationErrors.Count());
            Assert.AreEqual(@"The field param1 must match the regular expression '\d{1,3}'.", ex.OperationErrors.Single().Message);
        }
コード例 #8
0
        public void Query_Singleton_NoParams()
        {
            var proxy = DomainServiceProxy.Create <IMockDomainServiceContract, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Query));

            Assert.IsNull(this.OperationInvokedArgs);

            var result = proxy.GetSingletonEntity();

            Assert.IsNotNull(this.OperationInvokedArgs);
            Assert.IsNotNull(result);
            Assert.AreSame(MockDomainService.QueryReturnValue.First(), result);
            Assert.AreEqual("GetSingletonEntity", this.OperationInvokedArgs.Name);
            Assert.AreEqual(0, this.OperationInvokedArgs.Parameters.Count);
        }
コード例 #9
0
        public void Query_NoParams()
        {
            var proxy = DomainServiceProxy.Create <IMockDomainServiceContract, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Query));

            Assert.IsNull(this.OperationInvokedArgs);

            var result = proxy.GetEntities();

            Assert.IsNotNull(this.OperationInvokedArgs);
            Assert.IsNotNull(result);
            Assert.IsTrue(MockDomainService.QueryReturnValue.SequenceEqual(result));
            Assert.AreEqual("GetEntities", this.OperationInvokedArgs.Name);
            Assert.AreEqual(0, this.OperationInvokedArgs.Parameters.Count);
        }
コード例 #10
0
        public void Insert()
        {
            var proxy = DomainServiceProxy.Create <IMockDomainServiceContract, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Submit));

            Assert.IsNull(this.OperationInvokedArgs);

            var entity = proxy.GetSingletonEntity();

            proxy.InsertEntity(entity);
            Assert.IsNotNull(this.OperationInvokedArgs);
            Assert.AreEqual("InsertEntity", this.OperationInvokedArgs.Name);
            Assert.AreEqual(1, this.OperationInvokedArgs.Parameters.Count);
            Assert.AreSame(entity, this.OperationInvokedArgs.Parameters.Values.Single());
        }
コード例 #11
0
        public void InvokeOperation_NoParams()
        {
            var proxy = DomainServiceProxy.Create <IMockDomainServiceContract, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Invoke));

            Assert.IsNull(this.OperationInvokedArgs);

            var result = proxy.InvokeOperation();

            Assert.IsNotNull(this.OperationInvokedArgs);
            Assert.AreEqual(123, result);

            Assert.AreEqual("InvokeOperation", this.OperationInvokedArgs.Name);
            Assert.AreEqual(0, this.OperationInvokedArgs.Parameters.Count);
        }
コード例 #12
0
        public void Custom_NoParams()
        {
            var proxy = DomainServiceProxy.Create <IMockDomainServiceContract, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Submit));

            Assert.IsNull(this.OperationInvokedArgs);

            var entity = proxy.GetSingletonEntity();

            proxy.CustomMethod(entity);

            Assert.IsNotNull(this.OperationInvokedArgs);
            Assert.AreEqual("CustomMethod", this.OperationInvokedArgs.Name);
            Assert.AreEqual(1, this.OperationInvokedArgs.Parameters.Count);
            Assert.AreSame(entity, this.OperationInvokedArgs.Parameters["entity"]);
        }
コード例 #13
0
        public void Custom_ContinuableOperationError()
        {
            var proxy = DomainServiceProxy.Create <IMockDomainServiceContract, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Submit));

            Assert.IsNull(this.OperationInvokedArgs);

            var entity = proxy.GetSingletonEntity();

            entity.Name = "ThrowError";

            var ex = ExceptionHelper.ExpectException <OperationException>(
                () => proxy.CustomMethod(entity),
                Resource.DomainServiceProxy_OperationError);

            Assert.AreEqual(1, ex.OperationErrors.Count());
            Assert.AreEqual("ThrowError", ex.OperationErrors.Single().Message);
        }
コード例 #14
0
        public void InvokeOperation_WithParams()
        {
            var proxy = DomainServiceProxy.Create <IMockDomainServiceContract, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Invoke));

            Assert.IsNull(this.OperationInvokedArgs);

            var result = proxy.InvokeOperationWithParams(123, new[] { "a", "b", "c" }, null, null);

            Assert.IsNotNull(this.OperationInvokedArgs);
            Assert.AreEqual("123", result);

            Assert.AreEqual("InvokeOperationWithParams", this.OperationInvokedArgs.Name);
            Assert.AreEqual(4, this.OperationInvokedArgs.Parameters.Count);
            Assert.AreEqual((long)123, this.OperationInvokedArgs.Parameters["param1"]);
            Assert.AreEqual("abc", string.Join("", (string[])this.OperationInvokedArgs.Parameters["param2"]));
            Assert.AreEqual(null, this.OperationInvokedArgs.Parameters["param3"]);
            Assert.AreEqual(null, this.OperationInvokedArgs.Parameters["param4"]);
        }
コード例 #15
0
        public void Custom_WithParams()
        {
            var proxy = DomainServiceProxy.Create <IMockDomainServiceContract, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Submit));

            Assert.IsNull(this.OperationInvokedArgs);

            var entity = proxy.GetSingletonEntity();

            proxy.CustomMethodWithParams(entity, 123, new[] { "1", "2", "3" }, null, new Uri("http://param4", UriKind.Absolute));

            Assert.IsNotNull(this.OperationInvokedArgs);
            Assert.AreEqual("CustomMethodWithParams", this.OperationInvokedArgs.Name);
            Assert.AreEqual(5, this.OperationInvokedArgs.Parameters.Count);
            Assert.AreSame(entity, this.OperationInvokedArgs.Parameters["entity"]);
            Assert.AreEqual((long)123, this.OperationInvokedArgs.Parameters["param1"]);
            Assert.AreEqual("123", string.Join("", (string[])this.OperationInvokedArgs.Parameters["param2"]));
            Assert.AreEqual(null, this.OperationInvokedArgs.Parameters["param3"]);
            Assert.AreEqual("http://param4", ((Uri)this.OperationInvokedArgs.Parameters["param4"]).OriginalString);
        }
コード例 #16
0
        public void Query_Singleton_WithParams()
        {
            var proxy = DomainServiceProxy.Create <IMockDomainServiceContract, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Query));

            Assert.IsNull(this.OperationInvokedArgs);

            var result = proxy.GetSingletonEntityWithParams("param1", 2, 3, new Uri("http://param4", UriKind.Absolute));

            Assert.IsNotNull(this.OperationInvokedArgs);
            Assert.IsNotNull(result);
            Assert.AreSame(MockDomainService.QueryReturnValue.First(), result);
            Assert.AreEqual("GetSingletonEntityWithParams", this.OperationInvokedArgs.Name);

            // Verify parameters
            Assert.AreEqual(4, this.OperationInvokedArgs.Parameters.Count);
            Assert.AreEqual("param1", this.OperationInvokedArgs.Parameters["param1"]);
            Assert.AreEqual(2, this.OperationInvokedArgs.Parameters["param2"]);
            Assert.AreEqual((long)3, this.OperationInvokedArgs.Parameters["param3"]);
            Assert.AreEqual("http://param4", ((Uri)this.OperationInvokedArgs.Parameters["param4"]).OriginalString);
        }
コード例 #17
0
        public void Create_DomainServiceContext()
        {
            var context = new MockDomainServiceContext(DomainOperationType.Query);

            // Create proxy, verify it's not null.
            var proxy = DomainServiceProxy.Create <IMockDomainServiceContract, MockDomainService>(context);

            Assert.IsNotNull(proxy);

            // Examine its Context property
            PropertyInfo         contextProp  = proxy.GetType().GetProperty("Context");
            DomainServiceContext proxyContext = (DomainServiceContext)contextProp.GetGetMethod().Invoke(proxy, null);

            Assert.AreSame(context, proxyContext);

            // Examine its DomainServiceType property
            PropertyInfo typeProp  = proxy.GetType().GetProperty("DomainServiceType");
            Type         proxyType = (Type)typeProp.GetGetMethod().Invoke(proxy, null);

            Assert.AreEqual(typeof(MockDomainService), proxyType);
        }
コード例 #18
0
        public void Query_WithParams()
        {
            var proxy = DomainServiceProxy.Create <IMockDomainServiceContract, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Query));

            Assert.IsNull(this.OperationInvokedArgs);

            var result = proxy.GetEntitiesWithParams("123", 499, 501, new Uri("http://param4", UriKind.Absolute));

            // Verify results
            Assert.IsNotNull(this.OperationInvokedArgs);
            Assert.IsNotNull(result);
            Assert.IsTrue(MockDomainService.QueryReturnValue.SequenceEqual(result));
            Assert.AreEqual("GetEntitiesWithParams", this.OperationInvokedArgs.Name);

            // Verify parameters
            Assert.AreEqual(4, this.OperationInvokedArgs.Parameters.Count);
            Assert.AreEqual("123", this.OperationInvokedArgs.Parameters["param1"]);
            Assert.AreEqual(499, this.OperationInvokedArgs.Parameters["param2"]);
            Assert.AreEqual((long)501, this.OperationInvokedArgs.Parameters["param3"]);
            Assert.AreEqual("http://param4", ((Uri)this.OperationInvokedArgs.Parameters["param4"]).OriginalString);
        }
コード例 #19
0
 public static void Callback_MediumTrust_Proxies()
 {
     var proxy   = DomainServiceProxy.Create <IMockDomainServiceContract, MockDomainService>(new MockDomainServiceContext(DomainOperationType.Query));
     var results = proxy.GetEntities();
 }