public async Task Handle_ValidCommand_ShouldLoginSuccessfully(LoginOutput loginOutput) { // Arrange _mapperMock.Setup(m => m.Map <LoginOutput>(It.IsAny <User>())).Returns(loginOutput); // AutoMapper setup _appsettingMock.SetReturnsDefault(new AppSettings { Issuer = "key1", Secret = "kesdfaaaaaasffffffffy1" }); var sut = new LoginCommandHandler(_context, _mapperMock.Object, _appsettingMock.Object); // creating system under test var temUser = _fixture.Create <User>(); temUser.PasswordHash = "3pRTT3NlZJrki0wrSlmOjA=="; // Act await ContextOperation.CreateEntity(_context, temUser); var password = SecurityHelper.Decrypt(temUser.PasswordHash); var output = await sut.Handle(new LoginCommand { Email = temUser.Email, Password = password }, CancellationToken.None); // Assert Assert.True(!string.IsNullOrEmpty(output.Token)); }
public async Task Handle_ValidCommand_ShouldUpdateEntriesSuccessfully() { //Create entity to inserted and update var entity = _fixture.Create <Domain.Entities.Issue>(); // Arrange var issue = await ContextOperation.CreateEntity(_context, entity); // update properties issue.Title = _fixture.Create <string>(); // AutoMapper setup _mapperMock.Setup(m => m.Map(It.IsAny <UpdateIssueCommand>(), It.IsAny <Domain.Entities.Issue>())).Returns(issue); // creating System Under Test var sut = new UpdateIssueCommandHandler(_context, _mapperMock.Object); // Act await sut.Handle(new UpdateIssueCommand(), CancellationToken.None); // Assert var dbIssue = _context.Issues.First(); dbIssue.Title.ShouldBe(issue.Title); }
[HttpPost] //Always explicitly state the accepted HTTP method public IHttpActionResult Sub([FromBody] RootSubRequest rootRequest) { ContextOperation context = new ContextOperation(); RootSubResponse rootResponse = new RootSubResponse() { Difference = context.Diff(rootRequest.Minuend, rootRequest.Subtrahend) }; System.Net.Http.Headers.HttpRequestHeaders headers = this.Request.Headers; string XEviTrackingId = string.Empty; if (headers.Contains("XEviTrackingId")) { XEviTrackingId = headers.GetValues("XEviTrackingId").FirstOrDefault(); OperationDTO operation = new OperationDTO() { Calculation = (rootRequest.Minuend + context.BinaryOperationStrategy.OperatorCode + rootRequest.Subtrahend) + "=" + rootResponse.Difference, Id = XEviTrackingId, Date = DateTime.Now, Operation = context.BinaryOperationStrategy.Name }; this.journalDBOperations.PersistOperation(operation); } return(Ok(rootResponse)); }
[HttpPost] //Always explicitly state the accepted HTTP method public IHttpActionResult Mult([FromBody] RootMultRequest rootRequest) { ContextOperation context = new ContextOperation(); RootMultResponse rootResponse = new RootMultResponse() { Product = context.Multiply(rootRequest.Factors) }; System.Net.Http.Headers.HttpRequestHeaders headers = this.Request.Headers; string XEviTrackingId = string.Empty; if (headers.Contains("XEviTrackingId")) { XEviTrackingId = headers.GetValues("XEviTrackingId").FirstOrDefault(); OperationDTO operation = new OperationDTO() { Calculation = String.Join(context.MultipleArgsOperationStrategy.OperatorCode, rootRequest.Factors) + "=" + rootResponse.Product, Id = XEviTrackingId, Date = DateTime.Now, Operation = context.MultipleArgsOperationStrategy.Name }; this.journalDBOperations.PersistOperation(operation); } return(Ok(rootResponse)); }
[HttpPost] //Always explicitly state the accepted HTTP method public IHttpActionResult Div([FromBody] RootDivRequest rootRequest) { double remainder = 0; ContextOperation context = new ContextOperation(); RootDivResponse rootResponse = new RootDivResponse() { Quotient = context.Division(rootRequest.Dividend, rootRequest.Divisor, out remainder), Remainder = remainder }; System.Net.Http.Headers.HttpRequestHeaders headers = this.Request.Headers; string XEviTrackingId = string.Empty; if (headers.Contains("XEviTrackingId")) { XEviTrackingId = headers.GetValues("XEviTrackingId").FirstOrDefault(); OperationDTO operation = new OperationDTO() { Calculation = (rootRequest.Dividend + context.BinaryOperationStrategy.OperatorCode + rootRequest.Divisor) + "=" + rootResponse.Quotient, Id = XEviTrackingId, Date = DateTime.Now, Operation = context.BinaryOperationStrategy.Name }; this.journalDBOperations.PersistOperation(operation); } return(Ok(rootResponse)); }
[HttpPost] //Always explicitly state the accepted HTTP method public IHttpActionResult Sqrt([FromBody] RootSqrtRequest rootRequest) { ContextOperation context = new ContextOperation(); RootSqrtResponse rootResponse = new RootSqrtResponse() { Square = context.Square(rootRequest.Number), }; System.Net.Http.Headers.HttpRequestHeaders headers = this.Request.Headers; string XEviTrackingId = string.Empty; if (headers.Contains("XEviTrackingId")) { XEviTrackingId = headers.GetValues("XEviTrackingId").FirstOrDefault(); OperationDTO operation = new OperationDTO() { Calculation = (context.UnaryOperationStrategy.OperatorCode + rootRequest.Number) + "=" + rootResponse.Square, Id = XEviTrackingId, Date = DateTime.Now, Operation = context.UnaryOperationStrategy.Name }; this.journalDBOperations.PersistOperation(operation); } return(Ok(rootResponse)); }
public async Task Handle_GetAllQuery_ShouldReturnEntriesSuccessfully(List <IssueTypesDto> output) { // Arrange _mapperMock.Setup(m => m.Map <List <IssueTypesDto> >(It.IsAny <List <IssueType> >())).Returns(output); // AutoMapper setup var sut = new GetAllIssueTypesQueryHandler(_context, _mapperMock.Object); // creating system under test var temIssueType = _fixture.Create <IssueType>(); // Act await ContextOperation.CreateEntity(_context, temIssueType); var result = await sut.Handle(new GetAllIssueTypesQuery(), CancellationToken.None); // Assert result.Count().ShouldBeGreaterThan(0); }
public async Task Handle_ValidCommand_ShouldSaveEntriesSuccessfully(Domain.Entities.Issue Issue) { _fixture.RepeatCount = 0; // Arrange _mapperMock.Setup(m => m.Map <Domain.Entities.Issue>(It.IsAny <CreateIssueCommand>())) .Returns(Issue); // AutoMapper setup var sut = new CreateIssueCommandHandler(_context, _mapperMock.Object); // creating system under test var project = await ContextOperation.CreateEntity(_context, _fixture.Create <Project>()); // Act await sut.Handle(new CreateIssueCommand { ProjectId = project.Id }, CancellationToken.None); // Assert _context.Issues.Count().ShouldBe(1); }
public async Task Handle_ValidId_EntityShouldNotDeletedBecauseRelatedEntities() { _fixture.RepeatCount = 1; //Create entity to inserted and delete it var temProject = _fixture.Create <Project>(); // Arrange var project = await ContextOperation.CreateEntity(_context, temProject); var sut = new DeleteProjectCommandHandler(_context); // Assert await Assert.ThrowsAsync <DeleteFailureException>(() => sut.Handle(new DeleteProjectCommand { Id = project.Id, OwnerId = project.OwnerId }, CancellationToken.None)); }
public async Task Handle_ValidId_EntityShoulDeletedSuccessfully() { _fixture.RepeatCount = 0; //Create entity to inserted and delete it var temIssue = _fixture.Create <Domain.Entities.Issue>(); // Arrange var Issue = await ContextOperation.CreateEntity(_context, temIssue); var sut = new DeleteIssueCommandHandler(_context); // Act await sut.Handle(new DeleteIssueCommand { Id = Issue.Id }, CancellationToken.None); // Assert _context.Issues.Count().ShouldBe(0); }
public async Task Handle_ValidId_EntityShoulDeletedSuccessfully() { _fixture.RepeatCount = 0; //Create entity to inserted and delete it var temproject = _fixture.Create <Project>(); // Arrange var project = await ContextOperation.CreateEntity(_context, temproject); var sut = new DeleteProjectCommandHandler(_context); // Act await sut.Handle(new DeleteProjectCommand { Id = project.Id, OwnerId = project.OwnerId }, CancellationToken.None); // Assert _context.Projects.Count().ShouldBe(0); }
public async Task Handle_ValidCommand_ShouldSaveEntriesSuccessfully(Project Project) { _fixture.RepeatCount = 0; // Arrange _mapperMock.Setup(m => m.Map <Project>(It.IsAny <CreateProjectCommand>())).Returns(Project); // AutoMapper setup _mediatorMock.Setup(m => m.Publish(It.IsAny <CreateProjectParticipantsCommand>(), It.IsAny <CancellationToken>())); var sut = new CreateProjectCommandHandler(_context, _mapperMock.Object, _mediatorMock.Object); // creating system under test // Act var owner = _fixture.Create <User>(); await ContextOperation.CreateEntity(_context, owner); await sut.Handle(new CreateProjectCommand { OwnerId = owner.Id }, CancellationToken.None); // Assert _context.Projects.Count().ShouldBe(1); }
public StrategyReturnClass StrategyCalculate([FromBody] JsonStrategyParameter param) { StrategyReturnClass rtn = new StrategyReturnClass(); ContextOperation context = new ContextOperation(param.oper, param.NumberX, param.NumberY); try{ rtn.Message = "Calculated successfully by strategyPattern!"; rtn.result = context.Calculate(); rtn.ReturnValue = 0; } catch (Exception ex) { rtn.Message = "error:" + ex.Message; rtn.ReturnValue = 100; } finally { } return(rtn); }
/// <summary> /// Execute the column family operation against the connection to the server. /// </summary> /// <typeparam name="TResult"></typeparam> /// <param name="action"></param> /// <param name="throwOnError"></param> /// <returns></returns> public TResult ExecuteOperation <TResult>(ContextOperation <TResult> action, bool?throwOnError = null) { if (!throwOnError.HasValue) { throwOnError = ThrowErrors; } CassandraSession _localSession = null; if (CassandraSession.Current == null) { _localSession = new CassandraSession(); } try { LastError = null; TResult result; bool success = action.TryExecute(this, out result); if (!success) { LastError = action.Error; } if (!success && (throwOnError ?? ThrowErrors)) { throw action.Error; } return(result); } finally { if (_localSession != null) { _localSession.Dispose(); } } }
/// <summary> /// Initialize a new Context object. /// </summary> /// <param name="operation"> /// One of the <see cref="ContextOperation"/> enumerations indicating /// the type of operation under way. /// </param> /// <param name="objectType"> /// One of the <see cref="ContextObjectType"/> enumerations indicating /// the type of object (user or group) being used. /// </param> /// <param name="objectIdentifier"> /// A string containing the name of the object. This may be either a /// user/group name or a string representation of a SID. /// </param> /// <param name="target"> /// The target being operated on. /// </param> /// <param name="memberIdentifier"> /// A string containing the name of the member being added or removed /// from a group. Used only in such cases. /// </param> public Context(ContextOperation operation, ContextObjectType objectType, string objectIdentifier, object target, string memberIdentifier = null) { this.operation = operation; this.type = objectType; this.objectId = objectIdentifier; this.target = target; this.memberId = memberIdentifier; }