ABsoluteMaybe.Tests.Persistence.XmlExperimentCommandsTests.GetOrCreateParticipationRecordCreatesRecordAndReturnsItIfNotFound C# (CSharp) Method

GetOrCreateParticipationRecordCreatesRecordAndReturnsItIfNotFound() private method

        public void GetOrCreateParticipationRecordCreatesRecordAndReturnsItIfNotFound()
        {
            //arrange
            _commands.Reset();
            const string experimentName = "Troy's Experiment";
            const string assignedOption = "Foo";
            const string userId = "USER_123";
            _commands.GetOrCreateExperiment(experimentName, new[] { "Foo", "Bar" });

            //act
            var result = _commands.GetOrCreateParticipationRecord(experimentName, () => assignedOption, userId);

            //assert
            result.UserIdentifier.ShouldEqual(userId);
            result.AssignedOption.ShouldEqual(assignedOption);

            var xml = XDocument.Parse(_commands.SavedXml);
            var exp = xml.Root.Elements("Experiment").Single();

            var records = exp.Element("Participants").Elements("Participant");
            records.Count().ShouldEqual(1);

            var record = records.Single();
            record.Value.ShouldEqual(assignedOption);

            var userIdAtt = record.Attribute("Id");
            userIdAtt.ShouldNotBeNull();
            userIdAtt.Value.ShouldEqual(userId);
        }