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);
}