public async Task UpdateOrganisation_BusinessType_Should_Not_Remove_Organisation() { //Create new user var newUser = UserFactory.Create(userId, "testFirst", "testLast", "9999", "*****@*****.**"); //Create new org var country = context.Countries.Single(c => c.IsoAlpha2Code.Equals("gb")); var address = TestAddress(country); var org = new Organisation("SFW Ltd", BusinessType.LimitedCompany); try { context.Users.Add(newUser); await context.SaveChangesAsync(); context.Organisations.Add(org); await context.SaveChangesAsync(); //Assign org to user newUser.LinkToOrganisation(org); await context.SaveChangesAsync(); //Hold OrgID of newly created entity var oldOrgId = org.Id; //Update org with change in Business Type org = new Organisation("Name Changed", BusinessType.SoleTrader); context.Organisations.Add(org); await context.SaveChangesAsync(); //Update user with newly created org2 var user = await context.Users.SingleAsync(u => u.Id == newUser.Id); user.UpdateOrganisationOfUser(org); await context.SaveChangesAsync(); Assert.True(user.Organisation.Id == org.Id); //Both Orgs should have different OrgIds Assert.False(oldOrgId == org.Id); //Check if old org exists var oldExists = context.Organisations.Any(x => x.Id == oldOrgId); Assert.True(oldExists); //Check if new org exists var newExists = context.Organisations.Any(x => x.Id == org.Id); Assert.True(newExists); } finally { context.DeleteOnCommit(org); context.Entry(newUser).State = EntityState.Deleted; context.SaveChanges(); } }
public SharedUserRepositoryTests() { ownerUser = UserFactory.Create(Guid.NewGuid(), "Owner", "User", "12345", "*****@*****.**"); sharedUser = UserFactory.Create(Guid.NewGuid(), "Shared", "User", "12345", "*****@*****.**"); var userContext = A.Fake <IUserContext>(); A.CallTo(() => userContext.UserId).Returns(Guid.Parse(ownerUser.Id)); context = new IwsContext(userContext, A.Fake <IEventDispatcher>()); authorization = A.Fake <INotificationApplicationAuthorization>(); repository = new SharedUserRepository(context, authorization); preRunNotifications = context.NotificationApplications.Select(na => na.Id).ToArray(); notification = NotificationApplicationFactory.Create(Guid.Parse(ownerUser.Id), NotificationType.Recovery, UKCompetentAuthority.England, 20191); context.Users.Add(ownerUser); context.Users.Add(sharedUser); context.NotificationApplications.Add(notification); context.SaveChanges(); }
public CopyToNotificationHandlerTests() { var applicationRepository = A.Fake <INotificationApplicationRepository>(); SystemTime.Freeze(new DateTime(2015, 1, 1)); context = new IwsContext(GetUserContext(), A.Fake <IEventDispatcher>()); handler = new CopyToNotificationHandler(context, new NotificationToNotificationCopy(new WasteCodeCopy()), new ExporterToExporterCopy(), new TransportRouteToTransportRouteCopy(), new WasteRecoveryToWasteRecoveryCopy(), new ImporterToImporterCopy(), new NotificationApplicationRepository(context, new NotificationApplicationAuthorization(context, GetUserContext())), new IntraCountryExportAllowedRepository(context), new FacilityCollectionCopy(), new CarrierCollectionCopy(), new ProducerCollectionCopy(), new MeansOfTransportToMeansOfTransportCopy()); preRunNotifications = context.NotificationApplications.Select(na => na.Id).ToArray(); source = NotificationApplicationFactory.CreateCompleted(new Guid("0ED9A007-3C35-48A3-B008-9D5623FA5AD9"), UserId, context.Countries.ToArray(), context.WasteCodes.ToArray(), SourceNumber); destination = NotificationApplicationFactory.Create(UserId, DestinationNotificationType, DestinationCompetentAuthority, DestinationNumber); EntityHelper.SetEntityId(destination, new Guid("63581B29-EFB9-47F0-BCC3-E67382F4EAFA")); context.NotificationApplications.Add(source); context.NotificationApplications.Add(destination); // Calling source id and destination id is only safe after this call to save changes context.SaveChanges(); AddNotificationLinkedEntities(source.Id, destination.Id); context.AnnexCollections.Add(new AnnexCollection(destination.Id)); context.SaveChanges(); A.CallTo(() => applicationRepository.GetById(A <Guid> .Ignored)).Returns(source); }
public void CanCreateOrganisation() { var country = context.Countries.Single(c => c.IsoAlpha2Code.Equals("gb")); var address = TestAddress(country); var org = new Organisation("SFW Ltd", BusinessType.LimitedCompany); context.Organisations.Add(org); try { context.SaveChanges(); CleanUp(org); } catch (Exception) { if (Debugger.IsAttached) { Debugger.Break(); } throw; } }
public void Dispose() { var createdNotifications = context.NotificationApplications.Where(n => !preRunNotifications.Contains(n.Id)) .Select(n => n.Id) .ToArray(); foreach (var createdNotification in createdNotifications) { DatabaseDataDeleter.DeleteDataForNotification(createdNotification, context); } context.Entry(ownerUser).State = EntityState.Deleted; context.Entry(sharedUser).State = EntityState.Deleted; context.SaveChanges(); context.Dispose(); }
public async Task GetNotificationByIdChecksAuthorization() { var notification = NotificationApplicationFactory.Create(userId, NotificationType.Recovery, UKCompetentAuthority.England, 20181); context.NotificationApplications.Add(notification); context.SaveChanges(); var notificationId = notification.Id; var repository = new NotificationApplicationRepository(context, notificationApplicationAuthorization); await repository.GetById(notificationId); A.CallTo(() => notificationApplicationAuthorization.EnsureAccessAsync(notificationId)).MustHaveHappened(); context.DeleteOnCommit(notification); await context.SaveChangesAsync(); }