Ejemplo n.º 1
0
        public void TestEventsUnexpiredWrittenToFile() {
            // The current time, to the second.
            DateTime now = DateTime.Now;

            // When the event was logged.
            DateTime then = now.AddHours(-1);

            // Then, rounded to the nearest hour.
            var roundedThenHour = new DateTime(then.Year, then.Month, then.Day, then.Hour, 0, 0);

            var events = new EventsController();
            events.Shared.Variables.Tunnel(CommandBuilder.VariablesSet(CommonVariableNames.WriteLogEventsToFile, true.ToString()).SetOrigin(CommandOrigin.Local));

            events.Log(new GenericEvent() {
                Success = true,
                GenericEventType = GenericEventType.SecurityGroupAdded,
                Scope = new CommandData() {
                    Accounts = new List<AccountModel>() {
                        new AccountModel() {
                            Username = "******"
                        }
                    }
                },
                Stamp = now
            });

            events.Log(new GenericEvent() {
                Success = true,
                GenericEventType = GenericEventType.SecurityGroupAdded,
                Scope = new CommandData() {
                    Accounts = new List<AccountModel>() {
                        new AccountModel() {
                            Username = "******"
                        }
                    }
                },
                Stamp = then
            });

            events.WriteEvents(now);

            String logFileName = events.EventsLogFileName(roundedThenHour);



            var logEvent = JsonConvert.DeserializeObject<GenericEvent>(File.ReadAllText(logFileName).Trim(',', '\r', '\n'));

            Assert.IsTrue(logEvent.Success);
            Assert.AreEqual("SecurityGroupAdded", logEvent.Name);
            Assert.AreEqual("Phogue", logEvent.Scope.Accounts.First().Username);
        }