コード例 #1
0
        public void AssemblyDiscoveryActionDescriptionTest_actionDescription_BatchFromAttribute()
        {
            //arrange
            List <TypeInfo> types = new List <TypeInfo>();

            types.Add(typeof(BatchFromAttribute).GetTypeInfo());

            //act
            var response = AssemblyDiscoveryActionDescription.actionDescription(types.AsEnumerable());

            //assert
            Assert.NotNull(response);
            Assert.NotEmpty(response);
            Assert.Equal(2, response.Count());
            Assert.Collection(response.OrderBy(p => p.ActionName),
                              (p) => {
                Assert.Equal("BatchFromAttribute", p.BatchName);
                Assert.Equal("method1", p.ActionName);
                Assert.Equal(typeof(string), p.ReturnType);
            },
                              (p) => {
                Assert.Equal("BatchFromAttribute", p.BatchName);
                Assert.Equal("method2", p.ActionName);
                Assert.Equal(typeof(int), p.ReturnType);
            }
                              );
        }
コード例 #2
0
        public void DefaultBatchInvokerParameterBindingTest_Bind()
        {
            //Arange
            List <TypeInfo> types = new List <TypeInfo>();

            types.Add(typeof(SimplePOCOBatch).GetTypeInfo());
            var descriptions = AssemblyDiscoveryActionDescription.actionDescription(types);

            var batchParameterDictionary = new BatchParameterDictionary();

            batchParameterDictionary.Add("param1", "first param");

            var serializer = new Mock <IModelSerializer>(MockBehavior.Strict);

            var batchInvokerParameterBinding = new DefaultBatchInvokerParameterBinding(batchParameterDictionary, descriptions.Single((p) => p.ActionName.Equals("method3")).ActionInfo, serializer.Object);

            //Act
            var response = batchInvokerParameterBinding.Bind();

            //Assert
            Assert.NotNull(response);
            Assert.IsType <object[]>(response);
            Assert.Equal(1, response.Length);
            Assert.Equal("first param", response[0]);
        }
コード例 #3
0
        public async void DefaultBatchInvokerTest_invokeAsync()
        {
            //Arrange
            var propertyInvoker = new Mock <IPropertyInvoker>(MockBehavior.Strict);
            //var methodActivator = new Mock<MethodActivator>(MockBehavior.Strict);
            //methodActivator.Setup((s) => s.CreateInstance<object>(It.IsAny<IServiceProvider>(), It.IsAny<Type>()))
            var methodActivator = new MethodActivator();

            var isharpBatchTrackingActivator = new Mock <ISharpBatchTrackingFactory>(MockBehavior.Strict);

            isharpBatchTrackingActivator.Setup((s) => s.getTrakingProvider()).Returns(new TrackingMemory()).Verifiable();

            var modelSerializer = new Mock <IModelSerializer>(MockBehavior.Strict);

            modelSerializer.Setup((s) => s.Serialize((object)"method1")).Returns("\"method1\"");

            DefaultBatchInvoker defaultBatchInvoker = new DefaultBatchInvoker(
                propertyInvoker.Object,
                methodActivator,
                isharpBatchTrackingActivator.Object,
                modelSerializer.Object);

            var requestService = new Mock <IServiceProvider>(MockBehavior.Strict);

            requestService.Setup((s) => s.GetService(It.IsAny <Type>())).Returns((object)"Any").Verifiable();

            var httpRequest = new Mock <HttpRequest>(MockBehavior.Strict);

            httpRequest.Setup((s) => s.Path).Returns(new PathString("/batch/exec/batch/action"));
            httpRequest.Setup((s) => s.QueryString).Returns(new QueryString()).Verifiable();

            Stream bodyStream   = new MemoryStream();
            var    httpResponse = new Mock <HttpResponse>(MockBehavior.Strict);

            httpResponse.Setup((s) => s.Body).Returns(bodyStream).Verifiable();

            var context = new Mock <HttpContext>(MockBehavior.Strict);

            context.Setup((s) => s.Request).Returns(httpRequest.Object).Verifiable();
            context.Setup((s) => s.Response).Returns(httpResponse.Object).Verifiable();
            context.Setup((s) => s.RequestServices).Returns(requestService.Object).Verifiable();

            ContextInvoker contextInvoker = ContextInvoker.Create(context.Object);

            List <TypeInfo> types = new List <TypeInfo>();

            types.Add(typeof(SimplePOCOBatch).GetTypeInfo());
            var descriptions = AssemblyDiscoveryActionDescription.actionDescription(types);

            contextInvoker.ActionDescriptor = descriptions.First();

            //Act
            var response = await defaultBatchInvoker.InvokeAsync(contextInvoker);

            //Assert
            Assert.NotNull(response);
            Assert.Equal("\"method1\"", response);
        }
コード例 #4
0
        public async void BatchActionProviderTest_SimplePOCOBatchMethod1Invoke()
        {
            //Arrange
            List <TypeInfo> types = new List <TypeInfo>();

            types.Add(typeof(SimplePOCOBatch).GetTypeInfo());

            //act
            var actionDescriptions        = AssemblyDiscoveryActionDescription.actionDescription(types.AsEnumerable());
            var filteredActionDescription = actionDescriptions.Where(p => p.ActionName == "method1");


            var batchUrlManager = new Mock <IBatchUrlManager>(MockBehavior.Strict);

            batchUrlManager.Setup((s) => s.RequestCommand)
            .Returns(BatchUrlManagerCommand.Exec)
            .Verifiable();
            batchUrlManager.Setup((s) => s.isBatch).Returns(true).Verifiable();
            batchUrlManager.Setup((s) => s.RequestBatchName).Returns("SimplePOCO").Verifiable();
            batchUrlManager.Setup((s) => s.RequestBatchAction).Returns("method1").Verifiable();

            var context = new ContextInvoker()
            {
                ActionDescriptor = null,
                ActionName       = "method1",
                BatchName        = "SimplePOCO",
                SessionId        = Guid.NewGuid()
            };

            var applicationBatchManager = new Mock <IApplicationBatchManager>(MockBehavior.Strict);

            applicationBatchManager.Setup((s) => s.SearcByNameAndAction("SimplePOCO", "method1")).Returns(filteredActionDescription).Verifiable();

            var batchInvokerProvider = new Mock <IBatchInvokerProvider>(MockBehavior.Strict);

            batchInvokerProvider.Setup((s) => s.InvokeAsync(context)).Returns(Task.FromResult((object)"method1")).Verifiable();

            BatchActionProvider batchActionProvider = new BatchActionProvider(applicationBatchManager.Object, batchInvokerProvider.Object);

            //Act
            var result = await batchActionProvider.InvokeAsync(batchUrlManager.Object, context);

            //Assert
            Assert.NotNull(result);
            Assert.Equal("method1", result);
            Assert.Same(filteredActionDescription.First(), context.ActionDescriptor);
            batchInvokerProvider.Verify();
            applicationBatchManager.Verify();
        }
コード例 #5
0
        public void ConfigAttributeExecutorTest_Execute()
        {
            //Arrange
            List <TypeInfo> types = new List <TypeInfo>();

            types.Add(typeof(SimplePOCOConfgigurationAttributeBatch).GetTypeInfo());
            var actionsDescriptor        = AssemblyDiscoveryActionDescription.actionDescription(types.AsEnumerable());
            BatchActionDescriptor action = actionsDescriptor.First();

            var configureAttributeExecutor = new ConfigAttributeExecutor();

            //Act
            configureAttributeExecutor.execute(ref action);

            //Assert
            Assert.Equal("BatchName", action.BatchName);
        }
コード例 #6
0
        public async void BatchActionProviderTest_SimplePOCOBatchMultipleMethodMatch()
        {
            List <TypeInfo> types = new List <TypeInfo>();

            types.Add(typeof(SimplePOCOBatch).GetTypeInfo());

            //act
            var actionDescriptions = AssemblyDiscoveryActionDescription.actionDescription(types.AsEnumerable());


            var batchUrlManager = new Mock <IBatchUrlManager>(MockBehavior.Strict);

            batchUrlManager.Setup((s) => s.RequestCommand)
            .Returns(BatchUrlManagerCommand.Exec)
            .Verifiable();
            batchUrlManager.Setup((s) => s.isBatch).Returns(true).Verifiable();
            batchUrlManager.Setup((s) => s.RequestBatchName).Returns("SimplePOCO").Verifiable();
            batchUrlManager.Setup((s) => s.RequestBatchAction).Returns("method1").Verifiable();

            var context = new ContextInvoker()
            {
                ActionDescriptor = null,
                ActionName       = "method1",
                BatchName        = "SimplePOCO",
                SessionId        = Guid.NewGuid()
            };

            var applicationBatchManager = new Mock <IApplicationBatchManager>(MockBehavior.Strict);

            applicationBatchManager.Setup((s) => s.SearcByNameAndAction("SimplePOCO", "method1")).Returns(actionDescriptions).Verifiable();

            var batchInvokerProvider = new Mock <IBatchInvokerProvider>(MockBehavior.Strict);

            batchInvokerProvider.Setup((s) => s.InvokeAsync(context)).Returns(Task.FromResult((object)"method1")).Verifiable();

            BatchActionProvider batchActionProvider = new BatchActionProvider(applicationBatchManager.Object, batchInvokerProvider.Object);

            var response = await Assert.ThrowsAsync <Exception>(() => batchActionProvider.InvokeAsync(batchUrlManager.Object, context));

            Assert.Equal("Too many batch satisfy the search", response.Message);
        }