public async Task Should_Add_Project() { // Arrange Appointment expectedAppointment = AppointmentSeedData.RockingXMasConcert; #pragma warning disable EF1001 // Internal EF Core API usage. IStateManager iStateManager = Substitute.For <IStateManager>(); Model model = Substitute.For <Model>(); EntityEntry <Appointment> returnedEntityEntry = Substitute.For <EntityEntry <Appointment> >( #pragma warning disable EF1001 // Internal EF Core API usage. new InternalShadowEntityEntry( #pragma warning restore EF1001 // Internal EF Core API usage. iStateManager, #pragma warning disable EF1001 // Internal EF Core API usage. new EntityType("Appointment", model, ConfigurationSource.Convention))); #pragma warning restore EF1001 // Internal EF Core API usage. returnedEntityEntry.Entity.Returns(expectedAppointment); _arpaContext.Add(Arg.Any <Appointment>()) .Returns(returnedEntityEntry); _arpaContext.SaveChangesAsync(Arg.Any <CancellationToken>()) .Returns(1); // Act Appointment result = await _handler .Handle(new Logic.Appointments.Create.Command(), new CancellationToken()); // Assert result.Should().BeEquivalentTo(expectedAppointment); }
public async Task <MusicianProfile> Handle(Command request, CancellationToken cancellationToken) { var isFirstProfile = !(await _arpaContext.EntityExistsAsync <MusicianProfile>(mp => mp.PersonId == request.PersonId, cancellationToken)); var newMusicianProfile = new MusicianProfile(request, isFirstProfile); EntityEntry <MusicianProfile> createResult = _arpaContext.Add(newMusicianProfile); if (await _arpaContext.SaveChangesAsync(cancellationToken) > 0) { return(createResult.Entity); } throw new Exception($"Problem creating {nameof(MusicianProfile)}"); }
public virtual async Task <TEntity> Handle(ICreateCommand <TEntity> request, CancellationToken cancellationToken) { ConstructorInfo ctor = typeof(TEntity).GetConstructors() .First(c => c.IsPublic); ObjectActivator <TEntity> createdActivator = GetActivator <TEntity>(ctor); TEntity newEntity = createdActivator(Guid.NewGuid(), request); EntityEntry <TEntity> createResult = _arpaContext.Add(newEntity); if (await _arpaContext.SaveChangesAsync(cancellationToken) > 0) { return(createResult.Entity); } throw new Exception($"Problem creating {newEntity.GetType().Name}"); }
private async Task CreateRefreshTokenAsync(User user, string remoteIpAddress) { RefreshToken refreshToken = GernerateRefreshToken(user, remoteIpAddress); var cookieOptions = new CookieOptions { HttpOnly = true, Expires = refreshToken.ExpiryOn, IsEssential = true, SameSite = SameSiteMode.None, Secure = true }; _httpContextAccessor.HttpContext.Response.Cookies.Append("refreshToken", refreshToken.Token, cookieOptions); user.RefreshTokens.Add(refreshToken); _arpaContext.Add(refreshToken); if (!(await _arpaContext.SaveChangesAsync(new CancellationToken()) > 0)) { throw new Exception($"Problem creating {refreshToken.GetType().Name}"); } }