Ejemplo n.º 1
0
        public async Task <IActionResult> Delete(long id)
        {
            var service = new ExampleService(connString);
            var result  = await service.Delete(id);

            return(httpResult.Message(result.Code, result));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> All()
        {
            var service = new ExampleService(connString);
            var result  = await service.All();

            return(httpResult.Message(result.Code, result));
        }
        public async Task GetExampleTest()
        {
            var service = new ExampleService();
            var actual  = await service.GetFooAsync();

            Assert.Equal("Bar", actual);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([FromBody] ExampleModel data)
        {
            var service = new ExampleService(connString);
            var result  = await service.Create(data);

            return(httpResult.Message(result.Code, result));
        }
        public async Task OnMessageReceivedSadPath2()
        {
            var mockReceiver = new Mock <IReceiver>()
                               .SetupProperty(m => m.MessageHandler);
            var mockDatabase = new Mock <IDatabase>();

            var service = new ExampleService(mockReceiver.Object, mockDatabase.Object);

            await service.StartAsync(CancellationToken.None);

            var fakeMessage = new FakeReceiverMessage("MyPayload")
            {
                Headers = { ["operation"] = "invalid" }
            };

            await service.Receiver.MessageHandler.OnMessageReceivedAsync(mockReceiver.Object, fakeMessage);

            fakeMessage.HandledBy.Should().Be(nameof(fakeMessage.RejectAsync));

            mockDatabase.Verify(m => m.CreateAsync("MyPayload"), Times.Never());
            mockDatabase.Verify(m => m.UpdateAsync("MyPayload"), Times.Never());
            mockDatabase.Verify(m => m.DeleteAsync("MyPayload"), Times.Never());

            // TODO: Verify that the error log was sent
        }
Ejemplo n.º 6
0
        static Task TestRpcServer()
        {
            var config = new MqttConfiguration("Mqtt");

            config.ClientId = "Test JsonRpcMqtt" + Guid.NewGuid();
            config.Username = "******";
            config.Password = "******";

            var mqtt = new MqttClientHelper(config);


            var rpc = new Rpc(new JsonRpcMqttConnection(mqtt.Client, "test/", clientId: "TestRpcServer"));

            var functions = new ExampleService(rpc);

            rpc.Dispatcher.RegisterService(functions);

            mqtt.OnConnectionChange += (s, connected) => { if (connected)
                                                           {
                                                               rpc.UpdateRegisteredMethods();
                                                           }
            };

            return(mqtt.RunAsync());
        }
Ejemplo n.º 7
0
        public void SetUp()
        {
            _studentRepository       = new Mock <IRepository <Employee> >();
            _studentCourseRepository = new Mock <IRepository <StudentCourse> >();
            _courseRepository        = new Mock <IRepository <Course> >();

            _service = new ExampleService(_studentRepository.Object, _studentCourseRepository.Object, _courseRepository.Object);
        }
        public void TestResult()
        {
            var service = new ExampleService(Substitute.For <ILogger <ExampleService> >());

            var result = service.Test("Test");

            Assert.IsType <string>(result);
        }
Ejemplo n.º 9
0
        public void DisposeTest()
        {
            var repo    = new ExampleRepositoryMock();
            var example = new ExampleService(repo);

            example.Dispose();
            Assert.IsTrue(repo.Disposed);
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Update(long id, [FromBody] ExampleModel data)
        {
            data.Id = id;

            var service = new ExampleService(connString);
            var result  = await service.Update(data);

            return(httpResult.Message(result.Code, result));
        }
Ejemplo n.º 11
0
        public void AddFooBarObjectTest()
        {
            ExampleService svc = new ExampleService(context);

            int actual   = svc.AddFooBarObject();
            int expected = 1;

            Assert.AreEqual(actual, expected);
        }
        public void ConstructorHappyPath()
        {
            var receiver = new Mock <IReceiver>().Object;
            var database = new Mock <IDatabase>().Object;

            var service = new ExampleService(receiver, database);

            service.Receiver.Should().BeSameAs(receiver);
            service.Database.Should().BeSameAs(database);
        }
Ejemplo n.º 13
0
 /// <param name="subscriptionKey">LUIS Authoring Key</param>
 /// <param name="region">Regions currently available in West US, West Europe and Australia East".</param>
 public LuisProgClient(string subscriptionKey, Regions region)
 {
     Apps       = new AppService(subscriptionKey, region);
     Entities   = new EntityService(subscriptionKey, region);
     Examples   = new ExampleService(subscriptionKey, region);
     Intents    = new IntentService(subscriptionKey, region);
     Publishing = new PublishService(subscriptionKey, region);
     Versions   = new VersionService(subscriptionKey, region);
     Training   = new TrainingService(subscriptionKey, region);
 }
Ejemplo n.º 14
0
            public void Configure()
            {
#pragma warning disable 618
                using (OpenRastaConfiguration.Manual)
                {
                    ResourceSpace.Uses.Dependency(context => context.Singleton(() => new ExampleService()));
                }

                Resolved = resolver.Resolve <ExampleService>();
#pragma warning restore 618
            }
 public ExampleController(ExampleService ExampleService,
                          IExampleTransient transientExample,
                          IExampleScoped scopedExample,
                          IExampleSingleton singletonExample,
                          IExampleSingletonInstance singletonInstanceExample)
 {
     _exampleService           = ExampleService;
     _transientExample         = transientExample;
     _scopedExample            = scopedExample;
     _singletonExample         = singletonExample;
     _singletonInstanceExample = singletonInstanceExample;
 }
Ejemplo n.º 16
0
    protected override WebRequest GetWebRequest(Uri uri)
    {
        HttpWebRequest webRequest  = (HttpWebRequest)base.GetWebRequest(uri);
        ExampleService client      = new ExampleService();
        string         auth_id     = client.authenticate_get("www.testexample.com", "e5d30c56d600a7456846164");
        string         credentials =
            Convert.ToBase64String(Encoding.ASCII.GetBytes("www.testexample.com:e5d30c56d600a7456846164"));
        string credentials1 = Convert.ToBase64String(Encoding.ASCII.GetBytes(auth_id + ":"));

        webRequest.Headers["Authorization"] = "Basic " + credentials1;
        return(webRequest);
    }
Ejemplo n.º 17
0
        static Task TestRpcServer()
        {
            var listener = new Listener(8081);
            var rpc      = new Rpc(new JsonRcpHttpConnection(listener));

            var functions = new ExampleService(rpc);

            rpc.Dispatcher.RegisterService(functions);

            rpc.UpdateRegisteredMethods();

            return(listener.StartAsync());
        }
        public async Task StopAsyncHappyPath()
        {
            var mockReceiver = new Mock <IReceiver>()
                               .SetupProperty(m => m.MessageHandler);
            var database = new Mock <IDatabase>().Object;

            var service = new ExampleService(mockReceiver.Object, database);

            await service.StartAsync(CancellationToken.None);

            await service.StopAsync(CancellationToken.None);

            mockReceiver.Verify(m => m.Dispose(), Times.Once());
        }
Ejemplo n.º 19
0
        static void CommandPattern()
        {
            Console.WriteLine("\n\nCommandPattern Pattern");
            var history        = new History();
            var exampleService = new ExampleService("Initial value");
            var exampleCommand = new ExampleCommand(history, exampleService);
            var undoCommand    = new UndoCommand <string>(history);

            Console.WriteLine(exampleService.GetContent());
            exampleCommand.Execute();
            Console.WriteLine(exampleService.GetContent());
            undoCommand.Execute();
            Console.WriteLine(exampleService.GetContent());
        }
Ejemplo n.º 20
0
        public void TestGetServiceLogic()
        {
            var exampleService = new ExampleService("test message");
            var req            = new RequestJson();

            req.Name    = "sample";
            req.Message = "hello world";

            var res = exampleService.GetServiceLogic(req);

            Assert.Equal("SAMPLE", res.Name);
            Assert.Equal("HELLO WORLD", res.Message);
            Assert.Equal("test message", res.ServiceMessage);
        }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to insert an active Foo-Bar in database.");
            Console.ReadKey();

            using (ExampleMappingEntities db = new ExampleMappingEntities())
            {
                ExampleService svc = new ExampleService(db);

                int id = svc.AddFooBarObject();

                Console.WriteLine("An Foo-Bar object was added with ID " + id + ".");
                Console.ReadKey();
            }
        }
Ejemplo n.º 22
0
        public void Setup()
        {
            var logger = new Mock <ILogger <ExampleService> >();
            var mapper = AutoMapperFactory.GetMapper();

            repository = new Mock <IExampleRepository>();

            repository.Setup(r => r.Get()).Returns(ExampleMockResult.Get());
            repository.Setup(r => r.Get(It.IsAny <long>())).Returns(ExampleMockResult.Get().First());
            repository.Setup(r => r.Create(It.IsAny <List <ExampleModel> >())).Returns(1);
            repository.Setup(r => r.Modify(It.IsAny <ExampleModel>())).Returns(ExampleMockResult.Get().First());
            repository.Setup(r => r.Delete(It.IsAny <long>())).Returns(1);

            service = new ExampleService(repository.Object, logger.Object, mapper);
        }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            var    interceptor = new ServerInterceptor();
            Server server      = new Server
            {
                Services = { ExampleService.BindService(new ExampleServiceImpl()).Intercept(interceptor) },
                Ports    = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
            };

            server.Start();

            Console.WriteLine("Example server listening on port " + Port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();
        }
        public async Task StartAsyncHappyPath()
        {
            var mockReceiver = new Mock <IReceiver>()
                               .SetupProperty(m => m.MessageHandler);
            var mockDatabase = new Mock <IDatabase>();

            var receiver = mockReceiver.Object;

            var service = new ExampleService(receiver, mockDatabase.Object);

            receiver.MessageHandler.Should().BeNull();

            await service.StartAsync(CancellationToken.None);

            receiver.MessageHandler.Should().NotBeNull();

            mockReceiver.Verify(m => m.Dispose(), Times.Never());
        }
        protected async Task ExecuteBugCommand()
        {
            Debug.WriteLine("Executing..");
            try
            {
                var isOk = await ExampleService.ReproduceBug();

                if (isOk)
                {
                    Debug.WriteLine("Executed OK");
                    await App.Current.MainPage.DisplayAlert("Example", "Executed Ok", "Ok");
                }
                else
                {
                    Debug.WriteLine("Executed Failed");
                    await App.Current.MainPage.DisplayAlert("Example", "Executed Failed", "Ok");
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Executed error: " + e.Message);
            }
        }
        public async Task OnMessageReceivedHappyPath1()
        {
            var mockReceiver = new Mock <IReceiver>()
                               .SetupProperty(m => m.MessageHandler);
            var mockDatabase = new Mock <IDatabase>();

            var service = new ExampleService(mockReceiver.Object, mockDatabase.Object);

            await service.StartAsync(CancellationToken.None);

            var fakeMessage = new FakeReceiverMessage("MyPayload")
            {
                Headers = { ["operation"] = "create" }
            };

            await service.Receiver.MessageHandler.OnMessageReceivedAsync(mockReceiver.Object, fakeMessage);

            mockDatabase.Verify(m => m.CreateAsync("MyPayload"), Times.Once());
            fakeMessage.HandledBy.Should().Be(nameof(fakeMessage.AcknowledgeAsync));

            mockDatabase.Verify(m => m.UpdateAsync("MyPayload"), Times.Never());
            mockDatabase.Verify(m => m.DeleteAsync("MyPayload"), Times.Never());
        }
Ejemplo n.º 27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Load the config from the file.
            RpcConfigurationConfig config = LoadConfig(@".\GrpcServer.config");

            // Create the context.
            using (RpcConfigurationContext context = new RpcConfigurationContext(config, true))
            {
                Server server = new Server();

                server.Services.Add(context.Intercept(ExampleService.BindService(new ExampleServiceImpl()), "example1"));

                server.Ports.Add(context.GetServerPort("channel1"));

                server.Start();

                Console.WriteLine("The server has started.");
                Console.WriteLine("If you press any key, this application will terminate.");
                Console.ReadLine();
            }

            Console.WriteLine("The server has shutdown.");
            System.Threading.Thread.Sleep(1000);
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Constructor
 /// </summary>
 public ExampleV1Controller()
 {
     this.exampleService = new ExampleService();
 }
Ejemplo n.º 29
0
 public ExampleController(ExampleService exampleService)
 {
     _exampleService = exampleService;
 }
Ejemplo n.º 30
0
 public Context(ExampleService service)
 {
     Service = service;
 }
 public void SpinUp()
 {
     _repository = A.Fake<IRepository<Blog>>();
     _service = new ExampleService(_repository);
 }