public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IHandlerService, IHandlerRepository>(); var model = new ApiHandlerServerRequestModel(); var validatorMock = new Mock <IApiHandlerServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new HandlerService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALHandlerMapperMock, mock.DALMapperMockFactory.DALAirTransportMapperMock, mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock, mock.DALMapperMockFactory.DALOtherTransportMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <HandlerDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public async void Update() { var mock = new ServiceMockFacade <IHandlerRepository>(); var model = new ApiHandlerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Handler>())).Returns(Task.FromResult(new Handler())); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Handler())); var service = new HandlerService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLHandlerMapperMock, mock.DALMapperMockFactory.DALHandlerMapperMock, mock.BOLMapperMockFactory.BOLAirTransportMapperMock, mock.DALMapperMockFactory.DALAirTransportMapperMock, mock.BOLMapperMockFactory.BOLHandlerPipelineStepMapperMock, mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock, mock.BOLMapperMockFactory.BOLOtherTransportMapperMock, mock.DALMapperMockFactory.DALOtherTransportMapperMock); UpdateResponse <ApiHandlerResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiHandlerRequestModel>())); mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Handler>())); }
public void Start() { RequestRepository.Clear(); var buffer = new Buffer(BufferSize); var sourceService = new SourceService(RequestAmount, SourceAmount, SourceMinArg, SourceMaxArg); var handlerService = new HandlerService(HandlerAmount, HandlerMinArg, HandlerMaxArg); var dispatcher = new RequestDispatcher(buffer, sourceService, handlerService, RequestRepository); dispatcher.Start(); }
public async void Get_null_record() { var mock = new ServiceMockFacade <IHandlerRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Handler>(null)); var service = new HandlerService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLHandlerMapperMock, mock.DALMapperMockFactory.DALHandlerMapperMock, mock.BOLMapperMockFactory.BOLAirTransportMapperMock, mock.DALMapperMockFactory.DALAirTransportMapperMock); ApiHandlerResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void AirTransportsByHandlerId_Not_Exists() { var mock = new ServiceMockFacade <IHandlerRepository>(); mock.RepositoryMock.Setup(x => x.AirTransportsByHandlerId(default(int), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult <List <AirTransport> >(new List <AirTransport>())); var service = new HandlerService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLHandlerMapperMock, mock.DALMapperMockFactory.DALHandlerMapperMock, mock.BOLMapperMockFactory.BOLAirTransportMapperMock, mock.DALMapperMockFactory.DALAirTransportMapperMock); List <ApiAirTransportResponseModel> response = await service.AirTransportsByHandlerId(default(int)); response.Should().BeEmpty(); mock.RepositoryMock.Verify(x => x.AirTransportsByHandlerId(default(int), It.IsAny <int>(), It.IsAny <int>())); }
public async void All() { var mock = new ServiceMockFacade <IHandlerRepository>(); var records = new List <Handler>(); records.Add(new Handler()); mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); var service = new HandlerService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLHandlerMapperMock, mock.DALMapperMockFactory.DALHandlerMapperMock, mock.BOLMapperMockFactory.BOLAirTransportMapperMock, mock.DALMapperMockFactory.DALAirTransportMapperMock); List <ApiHandlerResponseModel> response = await service.All(); response.Should().HaveCount(1); mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>())); }
public async void Delete() { var mock = new ServiceMockFacade <IHandlerRepository>(); var model = new ApiHandlerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new HandlerService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLHandlerMapperMock, mock.DALMapperMockFactory.DALHandlerMapperMock, mock.BOLMapperMockFactory.BOLAirTransportMapperMock, mock.DALMapperMockFactory.DALAirTransportMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public static void Test1() { var amount = 100; var handlerIntensity = 1000; var sourceIntensity = 2; var requestRepo = new RequestRepositoryIml(); var buffer = new Buffer(1); var handlerService = new HandlerService(10, handlerIntensity, 100000); var sourceService = new SourceService(amount, 100, sourceIntensity, 1000); var dispatcher = new RequestDispatcher(buffer, sourceService, handlerService, requestRepo); dispatcher.Start(); Console.WriteLine( "HANDLED " + requestRepo.FindAll().Count(r => r.Status == Request.RequestStatus.HANDLED) + " REJECTED " + requestRepo.FindAll().Count(r => r.Status == Request.RequestStatus.REJECTED)); }
public async void Get_ShouldReturnRecords() { var mock = new ServiceMockFacade <IHandlerService, IHandlerRepository>(); var record = new Handler(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record)); var service = new HandlerService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Object, mock.DALMapperMockFactory.DALHandlerMapperMock, mock.DALMapperMockFactory.DALAirTransportMapperMock, mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock, mock.DALMapperMockFactory.DALOtherTransportMapperMock); ApiHandlerServerResponseModel response = await service.Get(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
public async void OtherTransportsByHandlerId_Exists() { var mock = new ServiceMockFacade <IHandlerService, IHandlerRepository>(); var records = new List <OtherTransport>(); records.Add(new OtherTransport()); mock.RepositoryMock.Setup(x => x.OtherTransportsByHandlerId(default(int), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records)); var service = new HandlerService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Object, mock.DALMapperMockFactory.DALHandlerMapperMock, mock.DALMapperMockFactory.DALAirTransportMapperMock, mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock, mock.DALMapperMockFactory.DALOtherTransportMapperMock); List <ApiOtherTransportServerResponseModel> response = await service.OtherTransportsByHandlerId(default(int)); response.Should().NotBeEmpty(); mock.RepositoryMock.Verify(x => x.OtherTransportsByHandlerId(default(int), It.IsAny <int>(), It.IsAny <int>())); }
public async Task afk(params string[] args) { string reason = "No reason provided"; if (args.Length > 0) { reason = string.Join(' ', args); } // Get the handler var handler = HandlerService.GetHandlerInstance <AfkHandler>(); if (handler.AfkStatus.ContainsKey(Context.User.Id)) { return; } handler.SetUserStatus(Context.User.Id, reason); await Context.Channel.SendMessageAsync("", false, new EmbedBuilder() { Title = $":wave: Goodbye {Context.User}", Description = "I've successfully set your AFK Status!", Fields = new List <EmbedFieldBuilder>() { new EmbedFieldBuilder() { Name = "Reason", Value = reason, } }, Footer = new EmbedFooterBuilder() { Text = "Afk set at" }, Color = Blurple }.WithCurrentTimestamp().Build()); }
public async void Delete_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IHandlerService, IHandlerRepository>(); var model = new ApiHandlerServerRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new HandlerService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Object, mock.DALMapperMockFactory.DALHandlerMapperMock, mock.DALMapperMockFactory.DALAirTransportMapperMock, mock.DALMapperMockFactory.DALHandlerPipelineStepMapperMock, mock.DALMapperMockFactory.DALOtherTransportMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.HandlerModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <HandlerDeletedNotification>(), It.IsAny <CancellationToken>())); }
/// <summary> /// Starts the HipBot application /// </summary> /// <param name="args">The command line arguments.</param> public void Initialize(string[] args) { // Load MEF DoImport(); // Register types Stencil.Defaults.Assemblies.Add(typeof(Room).Assembly); Stencil.Defaults.Assemblies.Add(typeof(Program).Assembly); Stencil.Defaults.Assemblies.Add(typeof(Stencil).Assembly); Stencil.Defaults.Assemblies.Add(typeof(ICommand).Assembly); // Register handlers foreach (var handler in Handlers) { Stencil.Defaults.Types.Add(handler.GetType()); } Stencil.Instance.Initilize(); // Start watching plugins InitializePluginWatcher(); // Initilize handler service handlerService = Stencil.Instance.Resolve <IHandlerService>() as HandlerService; // Run latest version var service = Stencil.Instance.Resolve <UpdateService>(); service.RunLatestVersion(true, false); // Get Console var console = Stencil.Instance.Resolve <HipBotConsole>(); // Go! console.Run(args); }
public async Task askstaff(params string[] args) { if (args.Length == 0) { await Context.Channel.SendMessageAsync("", false, new EmbedBuilder() { Title = "Huh?", Description = "You didn't provide any question to ask the staff", Color = Color.Red }.WithCurrentTimestamp().Build()); return; } string question = string.Join(' ', args); var handler = HandlerService.GetHandlerInstance <AskStaffHandler>(); if (handler == null) { Console.WriteLine("Handler null"); await Context.Channel.SendMessageAsync("", false, new EmbedBuilder() { Title = "Command unavailable", Description = "The bot needs to restart for this command to work. Please contact quin :/", Color = Color.Red, Footer = new EmbedFooterBuilder() { Text = "`handler`" }, }.WithCurrentTimestamp().Build()); return; } var result = handler.UserCanAsk(Context.User); if (!result.canAsk) { await Context.Channel.SendMessageAsync("", false, new EmbedBuilder() { Title = "Slow down there buddy!", Description = "You can only ask one question per hour!", Footer = new EmbedFooterBuilder() { Text = "You can ask again at" }, Timestamp = result.lastAskTime.AddHours(1), Color = Color.Red }.Build()); return; } var ico = Context.User.GetAvatarUrl(); if (ico == null) { ico = Context.User.GetDefaultAvatarUrl(); } var embed = new EmbedBuilder() { Author = new EmbedAuthorBuilder() { IconUrl = ico, Name = $"{Context.User}'s Question:" }, Description = question + $" []({Context.User.Id})", Color = Blurple }.WithCurrentTimestamp(); var message = await Global.AskStaffChannel.SendMessageAsync("", false, embed.Build()); handler.SetUserAsked(Context.User.Id, DateTime.UtcNow); var msg = await Context.Channel.SendMessageAsync("", false, new EmbedBuilder() { Title = "Success!", Description = $"Your question has been posted! You can click [Here]({message.GetJumpUrl()} \"liege is sexy also this is an easter egg?\") to view it!", Color = Color.Green, Footer = new EmbedFooterBuilder() { Text = "Asked at" } }.WithCurrentTimestamp().Build()); }
public async Task afk(params string[] args) { string reason = "No reason provided"; if (args.Length > 0) { reason = string.Join(' ', args); } // Get the handler var handler = HandlerService.GetHandlerInstance <AfkHandler>(); if (handler == null) { Console.WriteLine("Handler null"); await Context.Channel.SendMessageAsync("", false, new EmbedBuilder() { Title = "Command unavailable", Description = "The bot needs to restart for this command to work :/", Color = Color.Red, Footer = new EmbedFooterBuilder() { Text = "handler" }, }.WithCurrentTimestamp().Build()); return; } if (handler.AfkStatus == null) { await Context.Channel.SendMessageAsync("", false, new EmbedBuilder() { Title = "Command unavailable", Description = "The bot needs to restart for this command to work :/", Footer = new EmbedFooterBuilder() { Text = "handler.AfkStatus" }, Color = Color.Red }.WithCurrentTimestamp().Build()); return; } if (handler.AfkStatus.ContainsKey(Context.User.Id)) { return; } handler.SetUserStatus(Context.User.Id, reason); await Context.Channel.SendMessageAsync("", false, new EmbedBuilder() { Title = $":wave: Goodbye {Context.User}", Description = "I've successfully set your AFK Status!", Fields = new List <EmbedFieldBuilder>() { new EmbedFieldBuilder() { Name = "Reason", Value = reason, } }, Footer = new EmbedFooterBuilder() { Text = "Afk set at" }, Color = Blurple }.WithCurrentTimestamp().Build()); }
void OnMessageCallback(object parameters) { var e = (MessageEventArgs)parameters; HandlerService.Handle(e.Message, e.Room); }