public async Task BaseServiceProcessCallTest() { ISerializer serializer = new JsonSerializer(); var fooService = new FooService(); Assert.Equal("100.0", fooService.Id); var req = new FooReq { FooWord = "hello Tomato" }; var context1 = new MockContext(); var reqMessage = AmpMessage.CreateRequestMessage(100, 2); reqMessage.Version = 1; reqMessage.CodecType = CodecType.JSON; reqMessage.Sequence = 1; reqMessage.Data = serializer.Serialize(req); await fooService.ReceiveAsync(context1, reqMessage); Assert.NotNull(context1.ResponseMessage); Assert.Equal(0, context1.ResponseMessage.Code); Assert.NotNull(context1.ResponseMessage.Data); var res = serializer.Deserialize <FooRes>(context1.ResponseMessage.Data); Assert.NotNull(res); Assert.Equal(req.FooWord, res.RetFooWord); }
static void Main(string[] args) { var service = new FooService(); var result = service.Bar(); System.Console.WriteLine(result.b); }
public void insert_then_get() { using (ServiceContainer _container = new ServiceContainer()) { FooService fooService = _container.GetInstance <FooService>(); Foo foo = new Foo() { Name = "Tom Chen", Birthday_Title = DateTime.Now, Address = "Beijing" }; FooDTO fooDTO = Mapper.Map <FooDTO>(foo); var baseObj = fooService.Insert(fooDTO); var aa = fooService.GetById(baseObj.Id); Assert.AreEqual(baseObj.Id, aa.Id); Assert.AreEqual(baseObj.BirthDayTitle, aa.BirthDayTitle); Assert.AreEqual(baseObj.Name, aa.Name); Assert.AreEqual(baseObj.Address_title, aa.Address_title); List <int> ids = new List <int>() { 1, 2, 3, 4, 5, 6 }; var bb = fooService.GetByIds(ids); } }
public async Task TestFailThirdTrySmallTimeout() { var fooService = new FooService(); await AssertEx.WaitUntil(() => fooService.GetFooAsync()) .WithTimeout(TimeSpan.FromMilliseconds(1)) .IsTrue(f => f.Bar == "bar" && f.TryCount == 3); }
public void Reset_Should_Replace_Default() { var defaultCount = new InstanceCounter(); var simpleLazyFactory = SimpleLazyFactory <IFooService> .CreateForTest(); var defaultFunc = simpleLazyFactory.Default(() => new FooService(defaultCount)).Resolve; var instanceCount = new InstanceCounter(); var theOne = new FooService(instanceCount); var resetFunc = simpleLazyFactory.Reset(() => theOne).Resolve; var fooService = defaultFunc(); var fooService2 = resetFunc(); fooService.ShouldEqual(fooService2); for (int i = 0; i < 10; i++) { defaultFunc(); } for (int i = 0; i < 10; i++) { resetFunc(); } defaultCount.TotalCount.ShouldEqual(0); instanceCount.TotalCount.ShouldEqual(1); }
public void TestEnsureFooIsReturned() { var fooService = new FooService(); string foo = fooService.GetFoo(); Assert.Equal("Foo! Foo!", foo); }
public async Task <Option <IEnumerable <LogRecord> > > GetLogsFromFooService() { FooService fooService = new FooService(_logger); var logResult = await fooService.GenerateMockLogs(); return(Option <IEnumerable <LogRecord> > .ToOption(logResult?.Value)); }
static void Main(string[] args) { var request = "request"; var fooService = new FooService(); ServiceProxy.Invoke(r => fooService.DoFoo(request), "abc"); Console.Read(); }
static void Main(string[] args) { var request = "request"; var fooService = new FooService(); ServiceProxy.Invoke(fooService.DoFoo, "abc"); // lose the DoFoo parameter. Console.Read(); }
//Note the new parameter here: vvvvvvvvvvvvvvvvvvvvv public async Task Invoke(HttpContext context, FooService fooService) { context.Response.OnStarting(() => { var fooCount = fooService.Foos.Count; return(Task.CompletedTask); }); await _next(context); }
public void An_ArgumentException_is_raised() { // arrange var repo = new FooRepository(); var service = new FooService(repo); // act service.Execute(Guid.Empty); }
public void Bar_returns_value_tuple_correctly() { var sut = new FooService(); var actual = sut.Bar(); Assert.AreEqual(1, actual.a); Assert.AreEqual("Hello ValueTuple", actual.b); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, FooService service) { if (env.IsDevelopment()) { Console.WriteLine("We're in dev mode"); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "AllGames", template: "games/all", defaults: new { Controller = "Pages", Action = "Games" } ); routes.MapRoute( name: "AllMovies", template: "movies/all", defaults: new { Controller = "Pages", Action = "Movies" } ); }); // app.Run(async (context) => // { // var names = service.GetNames(); // StringBuilder builder = new StringBuilder(); // foreach (var name in names) // { // if (Configuration.GetValue<bool>("CapitalizedWords")) // { // builder.Append(name.ToUpper() + " "); // } // else // { // builder.Append(name + " "); // } // } // await context.Response.WriteAsync(builder.ToString()); // }); }
public void GetAllCustomers() { var _foo = new FooService(); customerEntity[] customers = _foo.getCustomerList; foreach (customerEntity customer in customers) { GetSingleCustomer(customer); } }
public void Static_Resolve_Default_Should_Call_Once() { for (int i = 0; i < 3; i++) { var fooService = FooService.Resolve(); fooService.Counter.TotalCount.ShouldEqual(1); } FooService.Resolve.ShouldEqual(SimpleLazyFactory <IFooService> .Instance.Resolve); }
public void Invoke_With_SyncCompletingHandler() { var service = new FooService(); var called = 0; String arg = null; var subscription = service.Changed.Subscribe( async x => { arg = x; called++; } ); Check.That(subscription) .IsInstanceOf <FuncSubscription <String> >(); Check.That(((FuncSubscription <String>)subscription).TestingGetPreviousSubscription()) .IsNull(); Check.That(((FuncSubscription <String>)subscription).Target) .IsNotNull(); Check.That(((FuncSubscription <String>)subscription).Method) .IsNotNull(); var flag1 = service.Do("abc"); Check.That(flag1) .IsTrue(); Check.That(called) .IsEqualTo(1); Check.That(arg) .IsEqualTo("abc"); called = 0; var flag2 = service.Do("def"); Check.That(flag2) .IsTrue(); Check.That(called) .IsEqualTo(1); Check.That(arg) .IsEqualTo("def"); Check.That(service.ChangedSource.NumberOfSubscriptions) .IsEqualTo(1); Check.That(service.ChangedSource.IsDisposed) .IsFalse(); }
public Application(ILogger <Application> logger , FooService fooService , BarService barService , BazService bazService) { _logger = logger; _fooService = fooService; _barService = barService; _bazService = bazService; }
public async Task Invoke_With_HandlerThrowingException_BeforeAwait() { var service = new FooService(); var called = 0; String arg = null; var subscription = service.Changed.SubscribeWeak( async x => { arg = x; called++; if (called == 1) { throw new ApplicationException(); } await Task.Yield(); } ); Check.That(subscription) .IsInstanceOf <FuncSubscription <String> >(); Check.That(((FuncSubscription <String>)subscription).TestingGetPreviousSubscription()) .IsInstanceOf <WeakSubscription <String> >(); Exception exception = null; using (EventSystem.UnobservedException.SubscribeWeak( x => Volatile.Write(ref exception, x) )) { var flag1 = await service.DoAsync("abc"); Check.That(flag1) .IsTrue(); Check.That(called) .IsEqualTo(1); Check.That(arg) .IsEqualTo("abc"); Check.That(Volatile.Read(ref exception)) .IsInstanceOf <ApplicationException>(); Check.That(service.ChangedSource.NumberOfSubscriptions) .IsEqualTo(1); Check.That(service.ChangedSource.IsDisposed) .IsFalse(); } }
[Test] // bug #81886 public void FaultTest() { IPEndPoint localEP = new IPEndPoint(IPAddress.Loopback, 5000); using (SocketResponder sr = new SocketResponder(localEP, s => FaultResponse_Qualified(s))) { FooService service = new FooService(); service.Url = "http://" + IPAddress.Loopback.ToString() + ":5000/"; try { service.Run(); Assert.Fail("#A1"); } catch (SoapException ex) { Assert.AreEqual("Mono Web Service", ex.Actor, "#A2"); Assert.AreEqual(SoapException.ServerFaultCode, ex.Code, "#A3"); Assert.IsNotNull(ex.Detail, "#A4"); Assert.AreEqual("detail", ex.Detail.LocalName, "#A5"); Assert.AreEqual("http://schemas.xmlsoap.org/soap/envelope/", ex.Detail.NamespaceURI, "#A6"); XmlNamespaceManager nsMgr = new XmlNamespaceManager(ex.Detail.OwnerDocument.NameTable); nsMgr.AddNamespace("se", "http://www.mono-project/System"); XmlElement systemError = (XmlElement)ex.Detail.SelectSingleNode( "se:systemerror", nsMgr); Assert.IsNotNull(systemError, "#A7"); Assert.IsNull(ex.InnerException, "#A8"); Assert.AreEqual("Failure processing request.", ex.Message, "#A9"); } service.Dispose(); } using (SocketResponder sr = new SocketResponder(localEP, s => FaultResponse_Unqualified(s))) { FooService service = new FooService(); service.Url = "http://" + IPAddress.Loopback.ToString() + ":5000/"; try { service.Run(); Assert.Fail("#B1"); } catch (SoapException ex) { Assert.AreEqual("Mono Web Service", ex.Actor, "#B2"); Assert.AreEqual(SoapException.ServerFaultCode, ex.Code, "#B3"); Assert.IsNotNull(ex.Detail, "#B4"); Assert.AreEqual("detail", ex.Detail.LocalName, "#B5"); Assert.AreEqual(string.Empty, ex.Detail.NamespaceURI, "#B6"); XmlNamespaceManager nsMgr = new XmlNamespaceManager(ex.Detail.OwnerDocument.NameTable); nsMgr.AddNamespace("se", "http://www.mono-project/System"); XmlElement systemError = (XmlElement)ex.Detail.SelectSingleNode( "se:systemerror", nsMgr); Assert.IsNotNull(systemError, "#B7"); Assert.IsNull(ex.InnerException, "#B8"); Assert.AreEqual("Failure processing request.", ex.Message, "#B9"); } service.Dispose(); } }
public void TestMethod2() { using (ServiceContainer _container = new ServiceContainer()) { Mock <BaseObjRepository> mock = new Mock <BaseObjRepository>(); mock.Setup(p => p.GetObj(It.IsAny <int>())).Returns(new Obj()); _container.Register <BaseObjRepository>(factory => mock.Object); _container.Register <FooService>(); FooService fooService = _container.GetInstance <FooService>(); } }
public AsyncInterceptorSampleService( IApplicationLifetime appLifetime, ApplicationDbContext dbContext, ILogger <AsyncInterceptorSampleService> logger, FooService service) { this.appLifetime = appLifetime; this.dbContext = dbContext; this.logger = logger; fooService = service; }
public void A_new_instance_is_created() { // arrange var repository = new FooRepository(); // act var service = new FooService(repository); // assert Assert.IsInstanceOf<FooService>(service); }
public ServiceProvider() { var fooService = new FooService(); var barService = new BarService(); Handlers = new Dictionary <Type, Action <object> > { { typeof(FooRequestA), request => fooService.ProcessA((FooRequestA)request) }, { typeof(FooRequestB), request => fooService.ProcessB((FooRequestB)request) }, { typeof(BarRequest), request => barService.Process((BarRequest)request) } }; }
public async Task TestWaitAll() { var fooService = new FooService(); await Task.WhenAll( AssertEx.WaitUntil(() => fooService.GetFooAsync()) .IsTrue(f => f.Bar == "bar"), AssertEx.WaitUntil(() => fooService.GetFooAsync()) .IsTrue(f => f.Bar == "bar")); AssertEx.IsTrue(() => fooService.TryCount == 2); }
[Test] // bug #81886 public void FaultTest () { IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 5000); using (SocketResponder sr = new SocketResponder (localEP, s => FaultResponse_Qualified (s))) { FooService service = new FooService (); service.Url = "http://" + IPAddress.Loopback.ToString () + ":5000/"; try { service.Run (); Assert.Fail ("#A1"); } catch (SoapException ex) { Assert.AreEqual ("Mono Web Service", ex.Actor, "#A2"); Assert.AreEqual (SoapException.ServerFaultCode, ex.Code, "#A3"); Assert.IsNotNull (ex.Detail, "#A4"); Assert.AreEqual ("detail", ex.Detail.LocalName, "#A5"); Assert.AreEqual ("http://schemas.xmlsoap.org/soap/envelope/", ex.Detail.NamespaceURI, "#A6"); XmlNamespaceManager nsMgr = new XmlNamespaceManager (ex.Detail.OwnerDocument.NameTable); nsMgr.AddNamespace ("se", "http://www.mono-project/System"); XmlElement systemError = (XmlElement) ex.Detail.SelectSingleNode ( "se:systemerror", nsMgr); Assert.IsNotNull (systemError, "#A7"); Assert.IsNull (ex.InnerException, "#A8"); Assert.AreEqual ("Failure processing request.", ex.Message, "#A9"); } service.Dispose (); } using (SocketResponder sr = new SocketResponder (localEP, s => FaultResponse_Unqualified (s))) { FooService service = new FooService (); service.Url = "http://" + IPAddress.Loopback.ToString () + ":5000/"; try { service.Run (); Assert.Fail ("#B1"); } catch (SoapException ex) { Assert.AreEqual ("Mono Web Service", ex.Actor, "#B2"); Assert.AreEqual (SoapException.ServerFaultCode, ex.Code, "#B3"); Assert.IsNotNull (ex.Detail, "#B4"); Assert.AreEqual ("detail", ex.Detail.LocalName, "#B5"); Assert.AreEqual (string.Empty, ex.Detail.NamespaceURI, "#B6"); XmlNamespaceManager nsMgr = new XmlNamespaceManager (ex.Detail.OwnerDocument.NameTable); nsMgr.AddNamespace ("se", "http://www.mono-project/System"); XmlElement systemError = (XmlElement) ex.Detail.SelectSingleNode ( "se:systemerror", nsMgr); Assert.IsNotNull (systemError, "#B7"); Assert.IsNull (ex.InnerException, "#B8"); Assert.AreEqual ("Failure processing request.", ex.Message, "#B9"); } service.Dispose (); } }
public void Invoke_With_HandlerThrowingException_AfterAwait() { var service = new FooService(); var called = 0; String arg = null; var subscription = service.Changed.Subscribe( async x => { arg = x; called++; await Task.Delay(10); throw new ApplicationException(); } ); Check.That(subscription) .IsInstanceOf <FuncSubscription <String> >(); Check.That(((FuncSubscription <String>)subscription).TestingGetPreviousSubscription()) .IsNull(); Exception exception = null; using (EventSystem.UnobservedException.SubscribeWeak( x => Volatile.Write(ref exception, x) )) { var flag1 = service.Do("abc"); Check.That(flag1) .IsTrue(); Check.That(called) .IsEqualTo(1); Check.That(arg) .IsEqualTo("abc"); SpinWait.SpinUntil(() => Volatile.Read(ref exception) != null, 2000); Check.That(Volatile.Read(ref exception)) .IsInstanceOf <ApplicationException>(); Check.That(service.ChangedSource.NumberOfSubscriptions) .IsEqualTo(1); Check.That(service.ChangedSource.IsDisposed) .IsFalse(); } }
public async Task Invoke_With_AlreadyCanceledHandler() { var service = new FooService(); var called = 0; String arg = null; var subscription = service.Changed.SubscribeWeak( x => { arg = x; called++; var cts = new CancellationTokenSource(); cts.Cancel(); return(Task.FromCanceled(cts.Token)); } ); Check.That(subscription) .IsInstanceOf <FuncSubscription <String> >(); Check.That(((FuncSubscription <String>)subscription).TestingGetPreviousSubscription()) .IsInstanceOf <WeakSubscription <String> >(); Exception exception = null; using (EventSystem.UnobservedException.SubscribeWeak( x => Volatile.Write(ref exception, x) )) { var flag1 = await service.DoAsync("abc"); Check.That(flag1) .IsTrue(); Check.That(called) .IsEqualTo(1); Check.That(arg) .IsEqualTo("abc"); Check.That(Volatile.Read(ref exception)) .IsNull(); Check.That(service.ChangedSource.NumberOfSubscriptions) .IsEqualTo(1); Check.That(service.ChangedSource.IsDisposed) .IsFalse(); } }
void serialized_Type_can_be_used_as_parameter_to_a_generic_function() { string stringType = typeof(TestClass).FullName ?? throw new InvalidOperationException(); var type = Type.GetType(stringType); var jsonString = GetTestObjectString(); IFooService component = new FooService(); dynamic actual = JsonSerializer.Deserialize(jsonString, type); var result = component.UseGeneric(actual); Assert.True(result == 0); }
public NewService(AuditableService <T> auditableService, FooService <T> fooService) { if (auditableService == null) { throw new ArgumentNullException("auditableService "); } if (fooService == null) { throw new ArgumentNullException("fooService"); } _auditableService = auditableService; _fooService = fooService; }
[Test] // bug #79988 public void OutParametersTest () { IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 5000); using (SocketResponder sr = new SocketResponder (localEP, s => OutParametersResponse (s))) { FooService service = new FooService (); service.Url = "http://" + IPAddress.Loopback.ToString () + ":5000/"; int a; bool b; Elem [] e = service.Req ("x", out a, out b); Assert.IsNull (e, "#A1"); Assert.AreEqual (0, a, "#A2"); Assert.IsFalse (b, "#A3"); service.Dispose (); } }
private void GracefulException() { try { var foo = new FooService(); foo.DangerousApi(); } catch (Exception ex) { _logger.Report(ex, new Dictionary <string, string> { { "loggerType", _logger.GetType().Name } }); Messages.Add($"{ex.GetType().Name}: {ex.Message}"); } }
public MainViewModel() { fooService = new FooService(); ClearCommand = new RelayCommand(() => { this.Foos.Clear(); this.GroupedFoos.Clear(); }); AboutCommand = new RelayCommand(() => { var navigationService = ServiceLocator.Current.GetInstance <NavigationService>(); navigationService.Navigate(typeof(AboutPage), null); }); }
static void Main () { IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 5000); using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (Response_Bug79988))) { sr.Start (); FooService service = new FooService (); service.Url = "http://" + IPAddress.Loopback.ToString () + ":5000/"; int a; bool b; Elem [] e = service.Req ("x", out a, out b); Assert.IsNull (e, "#A1"); Assert.AreEqual (0, a, "#A2"); Assert.IsFalse (b, "#A3"); } }
[Test] // bug #79988 public void OutParametersTest() { IPEndPoint localEP = new IPEndPoint(IPAddress.Loopback, 5000); using (SocketResponder sr = new SocketResponder(localEP, s => OutParametersResponse(s))) { FooService service = new FooService(); service.Url = "http://" + IPAddress.Loopback.ToString() + ":5000/"; int a; bool b; Elem [] e = service.Req("x", out a, out b); Assert.IsNull(e, "#A1"); Assert.AreEqual(0, a, "#A2"); Assert.IsFalse(b, "#A3"); service.Dispose(); } }
static void Main () { IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 5000); using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (Response_Bug80131))) { sr.Start (); FooService service = new FooService (); service.Url = "http://" + sr.LocalEndPoint.Address.ToString () + ":5000/"; int a; bool b; Elem [] e = service.Req ("x", out a, out b); Assert.IsNotNull (e, "#B1"); Assert.AreEqual (1, e.Length, "#B2"); Assert.AreEqual ("whatever", e [0].attr, "#B2"); Assert.AreEqual (5, a, "#B3"); Assert.IsTrue (b, "#B4"); } }
public void Invoke_With_AsyncCompletingHandler() { var service = new FooService(); var called = 0; String arg = null; var subscription = service.Changed.SubscribeWeak( async x => { await Task.Delay(100); arg = x; called++; } ); Check.That(subscription) .IsInstanceOf <FuncSubscription <String> >(); Check.That(((FuncSubscription <String>)subscription).TestingGetPreviousSubscription()) .IsInstanceOf <WeakSubscription <String> >(); var flag1 = service.Do("abc"); Check.That(flag1) .IsTrue(); Check.That(called) .IsEqualTo(0); SpinWait.SpinUntil(() => called == 1, 2000); Check.That(called) .IsEqualTo(1); Check.That(arg) .IsEqualTo("abc"); Check.That(service.ChangedSource.NumberOfSubscriptions) .IsEqualTo(1); Check.That(service.ChangedSource.IsDisposed) .IsFalse(); }
public void An_ArgumentNullException_is_raised() { // act var service = new FooService(null); }