public void FindAllExperimentsReturnsAllExperiments() { //arrange _commands.Reset(); // - experiment one _commands.GetOrCreateExperiment("Experiment1", new[] { "Experiment One", "Bar" }); _commands.GetOrCreateParticipationRecord("Experiment1", () => "Experiment One", "User 1"); // - experiment two _commands.GetOrCreateExperiment("Experiment2", new[] { "Foo", "Experiment Two" }); _commands.GetOrCreateParticipationRecord("Experiment2", () => "Experiment Two", "User 1"); _commands.GetOrCreateParticipationRecord("Experiment2", () => "Experiment Two", "User 2"); // - experiment three _commands.GetOrCreateExperiment("Experiment3", new[] { "Foo", "Bar" }); var queries = new XmlQueriesStub(_commands.SavedXml); //act var result = queries.FindAllExperiments(); //assert result.Count().ShouldEqual(3); result.ElementAt(0).Participants.Count().ShouldEqual(1); result.ElementAt(1).Participants.Count().ShouldEqual(2); result.ElementAt(2).Participants.Count().ShouldEqual(0); }
public void ConvertMarksOnlyExperimentsWithMatchingNameOrConversionKeyword() { //arrange _commands.Reset(); const string userId = "USER_123"; // - experiment one _commands.GetOrCreateExperiment("CORRECT_CONVERSION_KEYWORD", new[] { "Experiment One", "Bar" }); _commands.GetOrCreateParticipationRecord("CORRECT_CONVERSION_KEYWORD", () => "Experiment One", userId); // - experiment two _commands.GetOrCreateExperiment("Experiment2", new[] { "Foo", "Experiment Two" }); _commands.GetOrCreateParticipationRecord("Experiment2", () => "Experiment Two", userId); // - experiment three _commands.GetOrCreateExperiment("Experiment3", "CORRECT_CONVERSION_KEYWORD", new[] { "Experiment Three", "Bar" }); _commands.GetOrCreateParticipationRecord("Experiment3", () => "Experiment Three", userId); //act _commands.Convert("CORRECT_CONVERSION_KEYWORD", userId); //assert var xml = XDocument.Parse(_commands.SavedXml); var experiments = xml.Root.Elements("Experiment"); experiments.Count().ShouldEqual(3); var records = experiments.Aggregate(new List <XElement>(), (list, exp) => { var participants = exp.Element("Participants").Elements("Participant").Where( x => x.Attribute("HasConverted") != null && bool.Parse(x.Attribute("HasConverted").Value)); list.AddRange(participants); return(list); }, list => list); records.Count().ShouldEqual(2); }