Exemple #1
0
        public static void SyncCollectionByKey <TDbContext, TSource, TSourceItem, TDestination, TDestinationItem, TKey>
        (
            this IMemberConfigurationExpression <TSource, TDestination, ICollection <TDestinationItem> > config,
            IEntityFrameworkUnitOfWorkProvider <TDbContext> unitOfWorkProvider,
            Expression <Func <TSource, ICollection <TSourceItem> > > sourceCollectionSelector,
            Func <TSourceItem, TKey> sourceKeySelector,
            Func <TDestinationItem, TKey> destinationKeySelector,
            Func <TSourceItem, TDestinationItem> createFunction   = null,
            Action <TSourceItem, TDestinationItem> updateFunction = null,
            Action <TDestinationItem> removeFunction        = null,
            Func <TDestinationItem, bool> destinationFilter = null,
            bool keepRemovedItemsInDestinationCollection    = true
        )
            where TDbContext : DbContext
            where TDestinationItem : class
        {
            if (removeFunction == null)
            {
                removeFunction = d =>
                {
                    var uow = EntityFrameworkUnitOfWork.TryGetDbContext(unitOfWorkProvider);
                    uow.Set <TDestinationItem>().Remove(d);
                };
            }

            Extensions.SyncCollectionByKey(config, sourceCollectionSelector, sourceKeySelector, destinationKeySelector,
                                           createFunction, updateFunction, removeFunction, keepRemovedItemsInDestinationCollection,
                                           destinationFilter);
        }
        public void TestRemoveUser()
        {
            this.UserFacade.Save(new UserDTO()
            {
                Firstname = "test", IsEnable = true, Username = "******", Surname = "test", RoleId = this.AdminRoleID
            }, "testpass");
            using (var uow = this.UnitOfWorkProvider.Create())
            {
                var ctx = EntityFrameworkUnitOfWork.TryGetDbContext <NetfoxWebDbContext>(this.UnitOfWorkProvider);

                Assert.AreEqual(ctx.Users.Count(), 1);
            }

            var context = new TestDotvvmRequestContext()
            {
                Configuration       = this.Configuration,
                ApplicationHostPath = "../Netfox.Web.App/",
            };

            var viewModel = this.Container.Resolve <UserManagementViewModel>(new
            {
                Context = context,
            });

            viewModel.Init();
            viewModel.PreRender();
            viewModel.RemoveUser(viewModel.Helper.Items.Items.First().Id);

            using (var uow = this.UnitOfWorkProvider.Create())
            {
                var ctx = EntityFrameworkUnitOfWork.TryGetDbContext <NetfoxWebDbContext>(this.UnitOfWorkProvider);
                Assert.AreEqual(ctx.Users.Count(), 0);
            }
        }
        public void TestChangePassword()
        {
            var context = new TestDotvvmRequestContext()
            {
                Configuration       = this.Configuration,
                ApplicationHostPath = "../Netfox.Web.App/",
                Parameters          = new Dictionary <string, object>()
            };

            this.UserFacade.Save(new UserDTO()
            {
                Firstname = "test", IsEnable = true, Username = "******", Surname = "test", RoleId = this.AdminRoleID
            }, "testpass");

            var viewModel = this.Container.Resolve <ProfileViewModel>(new
            {
                Context  = context,
                Username = "******"
            });

            viewModel.User        = UserFacade.GetUser("testuser");
            viewModel.Password    = "******";
            viewModel.NewPassword = "******";
            viewModel.ChangePassword();

            using (var uow = this.UnitOfWorkProvider.Create())
            {
                var ctx      = EntityFrameworkUnitOfWork.TryGetDbContext <NetfoxWebDbContext>(this.UnitOfWorkProvider);
                var passHash = this.UserFacade.LoginFacade.SHA256Hash("newtestpass");
                Assert.AreEqual(ctx.Users.Count(u => u.Surname == "test" && u.Firstname == "test" && u.Username == "testuser" && u.Password == passHash), 1);
            }
        }
Exemple #4
0
        public void TestRemoveInvestigation()
        {
            this.AddUser();
            this.AddInvestigation();
            var context = new TestDotvvmRequestContext()
            {
                Configuration       = this.Configuration,
                ApplicationHostPath = "../Netfox.Web.App/"
            };
            var viewModel = this.Container.Resolve <InvestigationOverviewViewModel>(new
            {
                Context = context,
            });

            viewModel.Init();
            var currentUser = this.UserFacade.GetUser("testuser");

            this.InvestigationFacade.FillDataSet(viewModel.Helper.Items, viewModel.Helper.Filter, currentUser);
            viewModel.RemoveInvestigation(viewModel.Helper.Items.Items.First().Id);
            using (var uow = this.UnitOfWorkProvider.Create())
            {
                var ctx = EntityFrameworkUnitOfWork.TryGetDbContext <NetfoxWebDbContext>(this.UnitOfWorkProvider);
                Assert.AreEqual(ctx.Investigations.Count(), 0);
            }
        }
Exemple #5
0
        public static void SyncCollectionByKey <TDbContext, TSource, TSourceItem, TDestination, TDestinationItem>
        (
            this IMemberConfigurationExpression <TSource, TDestination, ICollection <TDestinationItem> > config,
            IEntityFrameworkUnitOfWorkProvider <TDbContext> unitOfWorkProvider,
            Expression <Func <TSource, ICollection <TSourceItem> > > sourceCollectionSelector,
            Func <TSourceItem, TDestinationItem> createFunction   = null,
            Action <TSourceItem, TDestinationItem> updateFunction = null,
            Action <TDestinationItem> removeFunction        = null,
            Func <TDestinationItem, bool> destinationFilter = null,
            bool keepRemovedItemsInDestinationCollection    = true
        )
            where TDbContext : DbContext
            where TDestinationItem : class
        {
            if (removeFunction == null)
            {
                removeFunction = d =>
                {
                    var dbContext = EntityFrameworkUnitOfWork.TryGetDbContext(unitOfWorkProvider);
                    dbContext.Set <TDestinationItem>().Remove(d);
                };
            }

            var sourceKeyEntityType = typeof(TSourceItem).GetTypeInfo()
                                      .GetInterfaces()
                                      .Select(s => s.GetTypeInfo())
                                      .SingleOrDefault(s => s.IsGenericType && s.GetGenericTypeDefinition() == typeof(IEntity <>));
            var sourceKeyType = sourceKeyEntityType?.GetGenericArguments()[0];

            var destinationKeyEntityType = typeof(TDestinationItem).GetTypeInfo()
                                           .GetInterfaces()
                                           .Select(s => s.GetTypeInfo())
                                           .SingleOrDefault(s => s.IsGenericType && s.GetGenericTypeDefinition() == typeof(IEntity <>));
            var destinationKeyType = destinationKeyEntityType?.GetGenericArguments()[0];

            if (sourceKeyType == null || destinationKeyType == null || sourceKeyType != destinationKeyType)
            {
                throw new InvalidOperationException(
                          "The source and destination collection items must implement the IEntity<TKey> interface and the keys must be equal!");
            }

            var sourceParam       = Expression.Parameter(typeof(TSourceItem), "i");
            var sourceKeySelector =
                Expression.Lambda(Expression.Property(sourceParam, nameof(IEntity <int> .Id)), sourceParam);
            var destinationParam       = Expression.Parameter(typeof(TDestinationItem), "i");
            var destinationKeySelector =
                Expression.Lambda(Expression.Property(destinationParam, nameof(IEntity <int> .Id)), destinationParam);

            var method = typeof(Extensions).GetTypeInfo().GetMethod("SyncCollectionByKeyReflectionOnly",
                                                                    BindingFlags.NonPublic | BindingFlags.Static);

            method.MakeGenericMethod(typeof(TSource), typeof(TSourceItem), typeof(TDestination),
                                     typeof(TDestinationItem), sourceKeyType)
            .Invoke(null,
                    new object[] {
                config, sourceCollectionSelector, sourceKeySelector, destinationKeySelector, createFunction,
                updateFunction, removeFunction, keepRemovedItemsInDestinationCollection, destinationFilter
            });
        }
Exemple #6
0
 public virtual void Clean()
 {
     using (var uow = this.UnitOfWorkProvider.Create())
     {
         var ctx = EntityFrameworkUnitOfWork.TryGetDbContext <NetfoxWebDbContext>(this.UnitOfWorkProvider);
         ctx.Database.Delete();
     }
 }
Exemple #7
0
        public void TryGetDbContext_UnitOfWorkRegistryHasNotUnitOfWork_ReturnsNull()
        {
            var dbContext = new Mock <DbContext>().Object;
            Func <DbContext> dbContextFactory = () => dbContext;
            var unitOfWorkRegistryStub        = new ThreadLocalUnitOfWorkRegistry();
            var unitOfWorkProvider            = new EntityFrameworkUnitOfWorkProvider(unitOfWorkRegistryStub, dbContextFactory);

            var value = EntityFrameworkUnitOfWork.TryGetDbContext(unitOfWorkProvider);

            Assert.Null(value);
        }
        public void TestEditDataUser()
        {
            this.Configuration.RouteTable.Add("Settings_UserManagement", "settings/User_management", "article.dothtml", null);
            var context = new TestDotvvmRequestContext()
            {
                Configuration       = this.Configuration,
                ApplicationHostPath = "../Netfox.Web.App/",
                Parameters          = new Dictionary <string, object>()
            };

            this.UserFacade.Save(new UserDTO()
            {
                Firstname = "test", IsEnable = true, Username = "******", Surname = "test", RoleId = this.AdminRoleID
            }, "testpass");
            var userId = new Guid();

            using (var uow = this.UnitOfWorkProvider.Create())
            {
                var ctx = EntityFrameworkUnitOfWork.TryGetDbContext <NetfoxWebDbContext>(this.UnitOfWorkProvider);
                userId = ctx.Users.First().Id;
            }
            context.Parameters.Add("UserId", userId);

            var viewModel = this.Container.Resolve <UserViewModel>(new
            {
                Context = context,
            });

            try
            {
                viewModel.UserId = userId;
                viewModel.Init();
                viewModel.PreRender();
                viewModel.User.IsEnable = false;
                viewModel.User.Surname  = "test2";
                viewModel.Save();
            }
            catch (DotvvmInterruptRequestExecutionException ex)
            {
                Assert.AreEqual(InterruptReason.Redirect, ex.InterruptReason);
                Assert.AreEqual(ex.CustomData, "~/settings/User_management");
                using (var uow = this.UnitOfWorkProvider.Create())
                {
                    var ctx      = EntityFrameworkUnitOfWork.TryGetDbContext <NetfoxWebDbContext>(this.UnitOfWorkProvider);
                    var passHash = this.UserFacade.LoginFacade.SHA256Hash("testpass");
                    Assert.AreEqual(ctx.Users.Count(u => u.Surname == "test2" && u.Firstname == "test" && u.Username == "testuser" && !u.IsEnable && u.Password == passHash), 1);
                }

                return;
            }
            Assert.Fail("A redirect should have been performed!");
        }
Exemple #9
0
        public void Map(IMapperConfigurationExpression cfg)
        {
            cfg.CreateMap <User, UserDTO>();
            cfg.CreateMap <User, PublicProfileDTO>()
            .BeforeMap((s, d) =>
            {
                // EF Core does not support lazy loading yet
                EntityFrameworkUnitOfWork.TryGetDbContext(uowProvider)
                .Entry(s)
                .Collection(x => x.WatchedAreas)
                .Load();
                EntityFrameworkUnitOfWork.TryGetDbContext(uowProvider)
                .Entry(s)
                .Collection(x => x.WatchedTags)
                .Load();
            })
            .ForMember(e => e.WatchedAreaIds, m => m.MapFrom(e => e.WatchedAreas.Select(a => a.AreaId)))
            .ForMember(e => e.WatchedTagIds, m => m.MapFrom(e => e.WatchedTags.Select(a => a.TagId)));

            cfg.CreateMap <PublicProfileDTO, User>()
            .BeforeMap((s, d) => {      // EF Core does not support lazy loading yet
                EntityFrameworkUnitOfWork.TryGetDbContext(uowProvider).Entry(d).Collection(x => x.WatchedAreas).Load();
                EntityFrameworkUnitOfWork.TryGetDbContext(uowProvider).Entry(d).Collection(x => x.WatchedTags).Load();
            })
            .ForMember(e => e.WatchedAreas, m => m.DropAndCreateCollection(uowProvider, x => x.WatchedAreaIds, x => new UserArea {
                AreaId = x
            }))
            .ForMember(e => e.WatchedTags, m => m.DropAndCreateCollection(uowProvider, x => x.WatchedTagIds, x => new UserTag {
                TagId = x
            }))
            .ForMember(e => e.DateCreated, m => m.Ignore())
            .ForMember(e => e.DateLastLogin, m => m.Ignore())
            .ForMember(e => e.Enabled, m => m.Ignore())
            .ForMember(e => e.Id, m => m.Ignore())
            .ForMember(e => e.UserName, m => m.Ignore())
            .ForMember(e => e.NormalizedUserName, m => m.Ignore())
            .ForMember(e => e.Email, m => m.Ignore())
            .ForMember(e => e.NormalizedEmail, m => m.Ignore())
            .ForMember(e => e.EmailConfirmed, m => m.Ignore())
            .ForMember(e => e.PasswordHash, m => m.Ignore())
            .ForMember(e => e.SecurityStamp, m => m.Ignore())
            .ForMember(e => e.ConcurrencyStamp, m => m.Ignore())
            .ForMember(e => e.PhoneNumber, m => m.Ignore())
            .ForMember(e => e.PhoneNumberConfirmed, m => m.Ignore())
            .ForMember(e => e.TwoFactorEnabled, m => m.Ignore())
            .ForMember(e => e.LockoutEnd, m => m.Ignore())
            .ForMember(e => e.LockoutEnabled, m => m.Ignore())
            .ForMember(e => e.AccessFailedCount, m => m.Ignore());

            cfg.CreateMap <User, UserBasicDTO>();
        }
Exemple #10
0
        public void TryGetDbContext_UnitOfWorkRegistryHasUnitOfWork_ReturnCorrectDbContext()
        {
            var dbContext = new Mock <DbContext>().Object;
            Func <DbContext> dbContextFactory = () => dbContext;
            var unitOfWorkRegistryStub        = new ThreadLocalUnitOfWorkRegistry();
            var unitOfWorkProvider            = new EntityFrameworkUnitOfWorkProvider(unitOfWorkRegistryStub, dbContextFactory);
            var unitOfWork = new EntityFrameworkUnitOfWork(unitOfWorkProvider, dbContextFactory, DbContextOptions.ReuseParentContext);

            unitOfWorkRegistryStub.RegisterUnitOfWork(unitOfWork);

            var uowDbContext = EntityFrameworkUnitOfWork.TryGetDbContext(unitOfWorkProvider);

            Assert.NotNull(uowDbContext);
            Assert.Same(dbContext, uowDbContext);
        }
Exemple #11
0
        public static void DropAndCreateCollection <TSource, TSourceItem, TDestination, TDestinationItem>
        (
            this IMemberConfigurationExpression <TSource, TDestination, ICollection <TDestinationItem> > config,
            IUnitOfWorkProvider unitOfWorkProvider,
            Expression <Func <TSource, ICollection <TSourceItem> > > sourceCollectionSelector,
            Func <TSourceItem, TDestinationItem> projection = null,
            Action <TDestinationItem> removeCallback        = null
        )
            where TDestinationItem : class
        {
            if (removeCallback == null)
            {
                removeCallback = item =>
                {
                    var uow = EntityFrameworkUnitOfWork.TryGetDbContext(unitOfWorkProvider);
                    uow.Set <TDestinationItem>().Remove(item);
                };
            }

            DropAndCreateCollection(config, sourceCollectionSelector, projection, removeCallback);
        }
Exemple #12
0
        public void TestAddInvestigation()
        {
            this.Configuration.RouteTable.Add("Investigations_overview", "Investigations/overview", "overview.dothtml", null);
            var context = new TestDotvvmRequestContext()
            {
                Configuration       = this.Configuration,
                ApplicationHostPath = "../Netfox.Web.App/",
                Parameters          = new Dictionary <string, object>()
            };

            this.AddUser();
            context.Parameters.Add("InvestigationId", Guid.Empty);
            var viewModel = this.Container.Resolve <InvestigationViewModel>(new
            {
                Context = context,
            });

            try
            {
                viewModel.Investigation = new InvestigationDTO()
                {
                    Name = "testInvestigation", Description = "Test Description.", Owner = this.UserFacade.GetUser("testuser")
                };
                viewModel.Save();
            }
            catch (DotvvmInterruptRequestExecutionException ex)
            {
                Assert.AreEqual(InterruptReason.Redirect, ex.InterruptReason);
                Assert.AreEqual(ex.CustomData, "~/Investigations/overview");
                using (var uow = this.UnitOfWorkProvider.Create())
                {
                    var ctx = EntityFrameworkUnitOfWork.TryGetDbContext <NetfoxWebDbContext>(this.UnitOfWorkProvider);
                    Assert.AreEqual(ctx.Investigations.Count(i => i.Name == "testInvestigation" && i.Description == "Test Description."), 1);
                }

                return;
            }

            Assert.Fail("A redirect should have been performed!");
        }
Exemple #13
0
        public virtual void SetUp()
        {
            Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory);
            this.Configuration = DotvvmConfiguration.CreateDefault();
            using (var uow = this.UnitOfWorkProvider.Create())
            {
                var ctx = EntityFrameworkUnitOfWork.TryGetDbContext <NetfoxWebDbContext>(this.UnitOfWorkProvider);
                ctx.Database.Delete();

                this.Roles.Insert(new Role()
                {
                    Name = "Administrator"
                });
                this.Roles.Insert(new Role()
                {
                    Name = "Investigator"
                });
                uow.Commit();
                //var ctx = EntityFrameworkUnitOfWork.TryGetDbContext<NetfoxWebDbContext>(this.UnitOfWorkProvider);
                this.AdminRoleID        = ctx.Roles.First(r => r.Name == "Administrator").Id;
                this.InvestigatorRoleID = ctx.Roles.First(r => r.Name == "Investigator").Id;
            }
        }
Exemple #14
0
        public void NestedDbContexts()
        {
            var registry = new ThreadLocalUnitOfWorkRegistry();
            var uowp1    = new EntityFrameworkUnitOfWorkProvider <CustomDbContext1>(registry, () => new CustomDbContext1());
            var uowp2    = new EntityFrameworkUnitOfWorkProvider <CustomDbContext2>(registry, () => new CustomDbContext2());

            using (var uow1 = uowp1.Create())
            {
                using (var uow2 = uowp2.Create())
                {
                    var current = registry.GetCurrent(0);
                    Assert.Equal(uow2, current);

                    var parent = registry.GetCurrent(1);
                    Assert.Equal(uow1, parent);

                    var inner = EntityFrameworkUnitOfWork.TryGetDbContext <CustomDbContext2>(uowp2);
                    Assert.Equal(((EntityFrameworkUnitOfWork <CustomDbContext2>)uow2).Context, inner);

                    var outer = EntityFrameworkUnitOfWork.TryGetDbContext <CustomDbContext1>(uowp1);
                    Assert.Equal(((EntityFrameworkUnitOfWork <CustomDbContext1>)uow1).Context, outer);
                }
            }
        }
Exemple #15
0
        public void TestInvestigationList()
        {
            var context = new TestDotvvmRequestContext()
            {
                Configuration       = this.Configuration,
                ApplicationHostPath = "../Netfox.Web.App/",
                Parameters          = new Dictionary <string, object>()
            };

            this.UserFacade.Save(new UserDTO()
            {
                Firstname = "test",
                IsEnable  = true,
                Username  = "******",
                Surname   = "test",
                RoleId    = AdminRoleID
            }, "testpass");

            this.UserFacade.Save(new UserDTO()
            {
                Firstname = "test",
                IsEnable  = true,
                Username  = "******",
                Surname   = "test",
                RoleId    = this.InvestigatorRoleID
            }, "testpass");

            this.UserFacade.Save(new UserDTO()
            {
                Firstname = "test",
                IsEnable  = true,
                Username  = "******",
                Surname   = "test",
                RoleId    = this.InvestigatorRoleID
            }, "testpass");

            this.InvestigationFacade.AddInvestigation(new InvestigationDTO()
            {
                Name        = "testInvestigation",
                Description = "Test Description.",
                OwnerID     = this.UserFacade.GetUser("admin").Id,
            }, new List <Guid>(), "../Netfox.Web.App/");

            this.InvestigationFacade.AddInvestigation(new InvestigationDTO()
            {
                Name        = "testInvestigation",
                Description = "Test Description.",
                OwnerID     = this.UserFacade.GetUser("owner").Id,
            }, new List <Guid>(), "../Netfox.Web.App/");

            var listID = new List <Guid>();

            using (var uow = this.UnitOfWorkProvider.Create())
            {
                var ctx = EntityFrameworkUnitOfWork.TryGetDbContext <NetfoxWebDbContext>(this.UnitOfWorkProvider);
                listID.Add(ctx.Users.SingleOrDefault(u => u.Username == "user").Id);
            }

            this.InvestigationFacade.AddInvestigation(new InvestigationDTO()
            {
                Name        = "testInvestigation",
                Description = "Test Description.",
                OwnerID     = this.UserFacade.GetUser("owner").Id,
            }, listID, "../Netfox.Web.App/");

            var viewModel = this.Container.Resolve <InvestigationOverviewViewModel>(new
            {
                Context = context,
            });

            viewModel.Init();

            this.InvestigationFacade.FillDataSet(viewModel.Helper.Items, new InvestigationFilterDTO(), this.UserFacade.GetUser("admin"));
            Assert.AreEqual(viewModel.Helper.Items.Items.Count, 3);
            this.InvestigationFacade.FillDataSet(viewModel.Helper.Items, new InvestigationFilterDTO(), this.UserFacade.GetUser("owner"));
            Assert.AreEqual(viewModel.Helper.Items.Items.Count, 2);
            this.InvestigationFacade.FillDataSet(viewModel.Helper.Items, new InvestigationFilterDTO(), this.UserFacade.GetUser("user"));
            Assert.AreEqual(viewModel.Helper.Items.Items.Count, 1);
        }
Exemple #16
0
        public void TestFramework_FTP()
        {
            this.Configuration.RouteTable.Add("Investigations_overview", "Investigations/overview", "overview.dothtml", null);
            var context = new TestDotvvmRequestContext()
            {
                Configuration       = this.Configuration,
                ApplicationHostPath = "../Netfox.Web.App/",
                Parameters          = new Dictionary <string, object>()
            };

            this.AddUser();
            this.AddInvestigation();

            Investigation investigation;

            using (var uow = this.UnitOfWorkProvider.Create())
            {
                var ctx = EntityFrameworkUnitOfWork.TryGetDbContext <NetfoxWebDbContext>(this.UnitOfWorkProvider);
                investigation = ctx.Investigations.First();
            }

            var NetfoxAPIFacadeFactory = this.Container.Resolve <Func <IWindsorContainer, Guid, string, NetfoxAPIFacade> >();
            var netfoxAPI = NetfoxAPIFacadeFactory(this.ContainerAPI, investigation.Id, Directory.GetCurrentDirectory());
            var snooper   = Container.Resolve <SnooperFTP.SnooperFTP>();

            Assert.NotNull(netfoxAPI);

            netfoxAPI.ProcessCapture(NetfoxWebTest.Default.FTPPcap);

            var capturelList = CaptureFacade.GetCaptureList(investigation.Id).ToList();

            Assert.AreEqual(capturelList.Count, 1);

            var l3    = new GridViewDataSet <L3ConversationDTO>();
            var l4    = new GridViewDataSet <L4ConversationDTO>();
            var l7    = new GridViewDataSet <L7ConversationDTO>();
            var frame = new GridViewDataSet <PmFrameBaseDTO>();

            l3.PagingOptions.PageSize        = 15;
            l3.SortingOptions.SortDescending = false;
            l3.SortingOptions.SortExpression = nameof(L3ConversationDTO.Id);

            l4.PagingOptions.PageSize        = 15;
            l4.SortingOptions.SortDescending = false;
            l4.SortingOptions.SortExpression = nameof(L4ConversationDTO.Id);

            l7.PagingOptions.PageSize        = 15;
            l7.SortingOptions.SortDescending = false;
            l7.SortingOptions.SortExpression = nameof(L7ConversationDTO.Id);

            frame.PagingOptions.PageSize        = 15;
            frame.SortingOptions.SortDescending = false;
            frame.SortingOptions.SortExpression = nameof(PmFrameBaseDTO.Id);

            this.CaptureFacade.FillL3ConversationDataSet(l3, capturelList.First().Id, investigation.Id, new ConversationFilterDTO());
            Assert.AreEqual(l3.PagingOptions.TotalItemsCount, 1);
            this.CaptureFacade.FillL4ConversationDataSet(l4, capturelList.First().Id, investigation.Id, new ConversationFilterDTO());
            Assert.AreEqual(l4.PagingOptions.TotalItemsCount, 5);
            this.CaptureFacade.FillL7ConversationDataSet(l7, capturelList.First().Id, investigation.Id, new ConversationFilterDTO());
            Assert.AreEqual(l7.PagingOptions.TotalItemsCount, 5);
            this.CaptureFacade.FillPmFrameDataSet(frame, capturelList.First().Id, investigation.Id, new FrameFilterDTO());
            Assert.AreEqual(frame.PagingOptions.TotalItemsCount, 69);

            var listSnooper = new List <string>();

            listSnooper.Add(snooper.GetType().FullName);

            netfoxAPI.ExportData(listSnooper);
            var exports = new GridViewDataSet <SnooperFTPListDTO>();

            exports.PagingOptions.PageSize        = 15;
            exports.SortingOptions.SortDescending = false;
            exports.SortingOptions.SortExpression = nameof(SnooperFTPListDTO.FirstSeen);

            ExportFTPFacade.FillDataSet(exports, investigation.Id, new ExportFilterDTO());

            Assert.AreEqual(exports.PagingOptions.TotalItemsCount, 21);
        }
Exemple #17
0
 public AppRoleStore(IUnitOfWorkProvider provider, IdentityErrorDescriber describer = null)
     : base((NemesisEventsContext)EntityFrameworkUnitOfWork.TryGetDbContext(provider), describer)
 {
     this.AutoSaveChanges = false;
 }
Exemple #18
0
        public void Map(IMapperConfigurationExpression cfg)
        {
            // Public
            cfg.CreateMap <Event, PublicUpcomingEventDTO>()
            .ForMember(e => e.HasAdmissionFee, m => m.MapFrom(e => !string.IsNullOrEmpty(e.AdmissionFee)))
            .ForMember(e => e.Tags, m => m.MapFrom(e => e.EventTags.Select(x => x.Tag.Name)));
            cfg.CreateMap <Event, PublicArchiveEventDTO>()
            .ForMember(e => e.Tags, m => m.MapFrom(e => e.EventTags.Select(x => x.Tag.Name)))
            .ForMember(e => e.HasVideo, m => m.MapFrom(e => !string.IsNullOrEmpty(e.VideoUrl)))
            .ForMember(e => e.HasSlides, m => m.MapFrom(e => e.Attachments.Any(a => a.Type == AttachmentType.Slides)))
            .ForMember(e => e.HasDemo, m => m.MapFrom(e => e.Attachments.Any(a => a.Type == AttachmentType.Demo)))
            .ForMember(e => e.HasPhotos, m => m.MapFrom(e => e.Attachments.Any(a => a.Type == AttachmentType.Photo)))
            .ForMember(e => e.HasOtherAttachments, m => m.MapFrom(e => e.Attachments.Any(a => a.Type == AttachmentType.Other)));

            // Admin
            cfg.CreateMap <Event, EventDTO>()
            .ForMember(e => e.HasAdmissionFee, m => m.MapFrom(e => !string.IsNullOrEmpty(e.AdmissionFee)));
            cfg.CreateMap <Event, OrganizedEventDTO>()
            .ForMember(e => e.HasVideo, m => m.MapFrom(e => !string.IsNullOrEmpty(e.VideoUrl)))
            .ForMember(e => e.HasSlides, m => m.MapFrom(e => e.Attachments.Any(a => a.Type == AttachmentType.Slides)))
            .ForMember(e => e.HasDemo, m => m.MapFrom(e => e.Attachments.Any(a => a.Type == AttachmentType.Demo)))
            .ForMember(e => e.HasPhotos, m => m.MapFrom(e => e.Attachments.Any(a => a.Type == AttachmentType.Photo)))
            .ForMember(e => e.HasAdmissionFee, m => m.MapFrom(e => !string.IsNullOrEmpty(e.AdmissionFee)))
            .ForMember(e => e.HasOtherAttachments, m => m.MapFrom(e => e.Attachments.Any(a => a.Type == AttachmentType.Other)));
            cfg.CreateMap <Event, EventDetailDTO>()
            .BeforeMap((s, d) => {      // EF Core does not support lazy loading yet
                EntityFrameworkUnitOfWork.TryGetDbContext(uowProvider).Entry(s).Collection(x => x.Attachments).Load();
                EntityFrameworkUnitOfWork.TryGetDbContext(uowProvider).Entry(s).Collection(x => x.EventTags).Load();
            })
            .ForMember(e => e.TagIds, m => m.MapFrom(e => e.EventTags.Select(t => t.TagId)));
            cfg.CreateMap <EventDetailDTO, Event>()
            .BeforeMap((s, d) => {      // EF Core does not support lazy loading yet
                EntityFrameworkUnitOfWork.TryGetDbContext(uowProvider).Entry(d).Collection(x => x.Attachments).Load();
                EntityFrameworkUnitOfWork.TryGetDbContext(uowProvider).Entry(d).Collection(x => x.EventTags).Load();
            })
            .ForMember(e => e.EventTags, m => m.DropAndCreateCollection(uowProvider, e => e.TagIds, e => new EventTag {
                TagId = e
            }))
            .ForMember(e => e.Venue, m => m.Ignore())
            .ForMember(e => e.Owner, m => m.Ignore())
            .ForMember(e => e.Attachments, m => m.Ignore())
            .ForMember(e => e.InvitationSent, m => m.Ignore())                                  // Do not automap invitation state
            .AfterMap((s, d) =>
            {
                // Persist invitation state for existing entries
                d.InvitationSent = s.Id == 0 ? false : d.InvitationSent;

                // save attachments (we cannot use SyncCollectionByKey because of EF Core bugs)
                foreach (var existing in d.Attachments)
                {
                    var sourceItem = s.Attachments.FirstOrDefault(e => e.Id == existing.Id);
                    if (sourceItem == null)
                    {
                        EntityFrameworkUnitOfWork.TryGetDbContext(uowProvider)
                        .Set <Attachment>().Remove(existing);
                    }
                    else
                    {
                        Mapper.Map(sourceItem, existing);
                        EntityFrameworkUnitOfWork.TryGetDbContext(uowProvider)
                        .Entry(existing).State = EntityState.Modified;
                    }
                }
                foreach (var addedItem in s.Attachments.Where(a => a.Id == 0))
                {
                    EntityFrameworkUnitOfWork.TryGetDbContext(uowProvider)
                    .Set <Attachment>().Add(Mapper.Map <Attachment>(addedItem));
                }
            });
        }