示例#1
0
        public void CreateForSetRequiredSigner_WhenRegistrationIsNull_Throws()
        {
            var exception = Assert.Throws <ArgumentNullException>(
                () => PackageRegistrationAuditRecord.CreateForSetRequiredSigner(
                    registration: null,
                    previousRequiredSigner: "a",
                    newRequiredSigner: "b"));

            Assert.Equal("registration", exception.ParamName);
        }
示例#2
0
        public void CreateForSetRequiredSigner_InitializesProperties(RequiredSignerTest test)
        {
            var record = PackageRegistrationAuditRecord.CreateForSetRequiredSigner(
                test.PackageRegistration, test.PreviousRequiredSigner, test.NewRequiredSigner);

            Assert.Equal(AuditedPackageRegistrationAction.SetRequiredSigner, record.Action);
            Assert.Equal(test.PackageRegistration.Id, record.Id);
            Assert.Equal(test.PreviousRequiredSigner, record.PreviousRequiredSigner);
            Assert.Equal(test.NewRequiredSigner, record.NewRequiredSigner);
            Assert.Null(record.Owner);
            Assert.Equal(test.PackageRegistration.Id, record.RegistrationRecord.Id);
        }
示例#3
0
        public void GetPath_ReturnsLowerCasedId()
        {
            var record = new PackageRegistrationAuditRecord(
                new PackageRegistration()
            {
                Id = "A"
            },
                AuditedPackageRegistrationAction.AddOwner,
                owner: "b");

            var actualPath = record.GetPath();

            Assert.Equal("a", actualPath);
        }
示例#4
0
        public void Constructor_SetsProperties()
        {
            var record = new PackageRegistrationAuditRecord(
                new PackageRegistration()
            {
                Id = "a"
            },
                AuditedPackageRegistrationAction.AddOwner,
                owner: "b");

            Assert.Equal("a", record.Id);
            Assert.NotNull(record.RegistrationRecord);
            Assert.Equal("a", record.RegistrationRecord.Id);
            Assert.Equal("b", record.Owner);
            Assert.Equal(AuditedPackageRegistrationAction.AddOwner, record.Action);
        }
        public static PackageRegistrationAuditRecord CreateForSetRequiredSigner(
            PackageRegistration registration,
            string previousRequiredSigner,
            string newRequiredSigner)
        {
            if (registration == null)
            {
                throw new ArgumentNullException(nameof(registration));
            }

            var record = new PackageRegistrationAuditRecord(
                registration,
                AuditedPackageRegistrationAction.SetRequiredSigner,
                owner: null);

            record.PreviousRequiredSigner = previousRequiredSigner;
            record.NewRequiredSigner      = newRequiredSigner;

            return(record);
        }
示例#6
0
        public async Task SaveAuditRecordAsync_PackageRegistrationAuditRecord()
        {
            var packageRegistration = new PackageRegistration()
            {
                DownloadCount = 1,
                Id            = "a",
                Key           = 2
            };
            var auditRecord = new PackageRegistrationAuditRecord(packageRegistration, AuditedPackageRegistrationAction.AddOwner, owner: "b");
            var service     = new TestAuditingService(async(string auditData, string resourceType, string filePath, string action, DateTime timestamp) =>
            {
                Assert.Equal("PackageRegistration", resourceType);
                Assert.Equal("a", filePath);
                Assert.Equal("addowner", action);
                Assert.InRange(timestamp, DateTime.UtcNow.AddMinutes(-1), DateTime.UtcNow.AddMinutes(1));

                var jObject = JObject.Parse(auditData);

                var record = jObject["Record"];

                Assert.Equal("a", record["Id"].Value <string>());

                var registrationRecord = record["RegistrationRecord"];

                Assert.Equal("a", registrationRecord["Id"].Value <string>());
                Assert.Equal(1, registrationRecord["DownloadCount"].Value <int>());
                Assert.Equal(2, registrationRecord["Key"].Value <int>());

                Assert.Equal("b", record["Owner"].Value <string>());
                Assert.Equal("AddOwner", record["Action"].Value <string>());

                await VerifyActor(jObject);

                return(null);
            });

            await service.SaveAuditRecordAsync(auditRecord);
        }