Beispiel #1
0
        public void DbContext_Update_CreatesAudit()
        {
            var(audits, dm) = GetUnitsOfWork();

            var ses = new DiscoverySession
            {
                AwsAccount = new AwsAccount {
                    Name = "foo"
                },
                RunDate = FixedDateTimeProvider.DateTime
            };

            dm.DiscoverySessions.Insert(ses, true);

            ses.RunDate = ses.RunDate.AddDays(1);
            dm.DiscoverySessions.Update(ses, true);

            var audit = audits.GetAll().Last();

            Assert.AreEqual(FixedDateTimeProvider.DateTime, audit.Date);
            Assert.AreEqual(DefaultUserProvider.UserId, audit.UserId);
            Assert.AreEqual(typeof(DiscoverySession).Name, audit.EntityName);
            Assert.AreEqual($"\"Id\":{ses.Id},\"AwsAccountId\":{ses.AwsAccountId},\"RunDate\":\"2001-01-01T00:00:00\"", audit.OldValue);
            Assert.AreEqual($"\"Id\":{ses.Id},\"AwsAccountId\":{ses.AwsAccountId},\"RunDate\":\"2001-01-02T00:00:00\"", audit.NewValue);
        }
        public DiscoverySessionViewModel(DiscoverySession discoverySession)
        {
            if (discoverySession == null)
            {
                throw new ArgumentNullException(nameof(discoverySession));
            }

            Id             = discoverySession.Id;
            RunDate        = discoverySession.RunDate;
            AwsAccountName = discoverySession.AwsAccount.Name;
        }
        private Dictionary <IPAddress, AwsInstance> InsertDependencies(DiscoverySession ds, IEnumerable <DependencyInfo> dependencies)
        {
            ds           = ds ?? throw new Exception(nameof(ds));
            dependencies = dependencies ?? throw new ArgumentNullException(nameof(dependencies));

            var instances = new Dictionary <IPAddress, AwsInstance>();
            var deps      = new Dictionary <(IPAddress src, IPAddress dst), Dependency>();

            foreach (var depInfo in dependencies)
            {
                ValidateDependency(depInfo, nameof(dependencies));

                var source = instances.GetOrAdd(depInfo.Source, () => new AwsInstance
                {
                    IpAddress        = depInfo.Source,
                    DiscoverySession = ds
                });

                var target = instances.GetOrAdd(depInfo.Target, () => new AwsInstance
                {
                    IpAddress        = depInfo.Target,
                    DiscoverySession = ds
                });

                var dep = deps.GetOrAdd((depInfo.Source, depInfo.Target), () => new Dependency
                {
                    SourceAwsInstance = source,
                    TargetAwsInstance = target
                });

                var finding = new DependencyFinding
                {
                    FileName   = depInfo.FileName,
                    Text       = depInfo.Text,
                    Dependency = dep
                };

                _context.DependencyFindings.Insert(finding);
            }

            if (instances.Count == 0)
            {
                throw new ArgumentException("Discovery session contains no findings.", nameof(dependencies));
            }

            return(instances);
        }
        public async Task <DiscoverySession> InsertDiscoverySessionAsync(DiscoverySessionInfo session)
        {
            session = session ?? throw new ArgumentNullException(nameof(session));

            var ds = new DiscoverySession
            {
                AwsAccountId = session.AwsAccountId,
                RunDate      = _dateTimeProvider.Now()
            };

            var instances = InsertDependencies(ds, session.Dependencies);

            InsertDiscoveryReports(instances, session.DiscoveryReports);

            await _context.CommitAsync();

            return(ds);
        }