Esempio n. 1
0
        public void AddEntry(Entry entry)
        {
            if (entry == null)
                throw new ArgumentNullException("Entry");
            if (string.IsNullOrEmpty(entry.UserId))
                throw new ArgumentNullException("UserId");

            var now = _timeService.GetNow();

            if (_entryRepository.IsEmpty(entry.UserId))
                AddFirstOffTheGridEntry(entry.UserId, now);

            var location = _locationRepository.Find(entry.Location.Name, entry.UserId);
            var tag = _tagRepository.Find(entry.Tag.Name, entry.UserId);
            var latestEntry = _entryRepository.GetLatestEntry(entry.UserId);

            if (latestEntry != null)
            {
                latestEntry.StoppedOn = now;
                _entryRepository.Update(latestEntry);
            }

            entry.Location = location == null ? AddLocationBasedOnEntry(entry) : location;
            entry.Tag = tag == null ? AddTagBasedOnEntry(entry) : tag;
            entry.CreatedOn = _timeService.GetNow();

            _entryRepository.Add(entry);

            _unitOfWork.Commit();
        }
Esempio n. 2
0
        public void Test_AddEntry_Adds_Unresolvable_EntryTag()
        {
            var entryRepository = new Mock<IEntryRepository>();
            var locationRepository = new Mock<ILocationRepository>();
            var tagRepository = new Mock<ITagRepository>();
            var timeLineServiceStub = new Mock<ITimelineColorService>();
            var timeServiceStub = new Mock<ITimeService>();
            var unitOfWorkStub = new Mock<IUnitOfWork>();

            entryRepository.Setup(e => e.IsEmpty(It.IsAny<string>()))
                            .Returns(false);
            tagRepository.Setup(l => l.Find(It.IsAny<string>(), It.IsAny<string>()))
                                .Returns((EntryTag)null);
            timeLineServiceStub.Setup(t => t.GetRandom())
                            .Returns(new TimelineColor("#FFF"));

            var entryService = new Mock<EntryService>(
               entryRepository.Object,
               locationRepository.Object,
               tagRepository.Object,
               timeLineServiceStub.Object,
               timeServiceStub.Object,
               unitOfWorkStub.Object);

            var newEntry = new Entry()
            {
                Location = new Location() { Name = "Test_Location_Name" },
                Tag = new EntryTag() { Name = "Unresolvable_Tag_Name" },
                UserId = "1"
            };

            entryService.Object.AddEntry(newEntry);

            tagRepository.Verify(e => e.Add(It.IsAny<EntryTag>()), Times.Once());
        }
        public void Initialize()
        {
            var addEntryViewModel =  new AddEntryViewModel()
            {
                TagName = "TagTest",
                LocationName = "LocationTest",
                Description = "MetaTest"
            };

            _extractedEntry = addEntryViewModel.ExtractEntry();
        }
        public static Entry ExtractEntry(this AddEntryViewModel addEntryViewModel)
        {
            var entry = new Entry();

            entry.Tag = new EntryTag();
            entry.Tag.Name = addEntryViewModel.TagName;
            entry.Location = new Location();
            entry.Location.Name = addEntryViewModel.LocationName;
            entry.Description = addEntryViewModel.Description;

            return entry;
        }
Esempio n. 5
0
        public void Test_AssembleHomeStatisticsViewModel_Fills_In_LatestEntry()
        {
            var entryService = new Mock<IEntryService>();

            var anyEntry = new Entry() { CreatedOn = new DateTime(2010, 10, 8) };

            entryService
                .Setup(e => e.GetLatestEntry(It.IsAny<string>()))
                .Returns(anyEntry);

            var statisticsAssembler = new StatisticsAssembler(entryService.Object);

            var statisticsViewModel = statisticsAssembler.AssembleHomeStatisticsViewModel(It.IsAny<string>());

            Assert.IsTrue(statisticsViewModel.HasLatestEntry);
            Assert.IsNotNull(statisticsViewModel.LatestEntry);
        }
Esempio n. 6
0
        public void Test_Fills_In_LatestEntry()
        {
            var entryService = GetEntryService();

            var anyEntry = new Entry() { CreatedOn = new DateTime(2010, 10, 8) };

            entryService
                .Setup(e => e.GetLatestEntry(It.IsAny<string>()))
                .Returns(anyEntry);

            var statisticsAssembler = new StatisticsAssembler(
                entryService.Object, GetDefaultTimeService().Object, GetDefaultUserSettingsService().Object);

            var statisticsViewModel = new HomeStatisticsViewModel(_baseDateTime, _baseDateTime.AddDays(3));
            var statisticsViewModelResult = statisticsAssembler.AssembleHomeStatisticsViewModel(statisticsViewModel, It.IsAny<string>());

            Assert.IsTrue(statisticsViewModelResult.HasLatestEntry);
            Assert.IsNotNull(statisticsViewModelResult.LatestEntry);
        }
Esempio n. 7
0
        private EntryTag AddTagBasedOnEntry(Entry entry)
        {
            var randomColor = _timelineColorService.GetRandom().Value;

            var tag = new EntryTag(entry.Tag.Name, randomColor, entry.UserId);

            return _tagRepository.Add(tag);
        }
Esempio n. 8
0
        private Location AddLocationBasedOnEntry(Entry entry)
        {
            var location = new Location(entry.Location.Name, entry.UserId);

            return _locationRepository.Add(location);
        }
Esempio n. 9
0
        private void AddFirstOffTheGridEntry(string userId, DateTime stoppedOn)
        {
            var offTheGridTag = AddOffTheGridTag(userId);
            var offTheGridLocation = AddOffTheGridLocation(userId);

            var offTheGridEntry = new Entry()
            {
                CreatedOn = new DateTime(2010, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc),
                Description = "Off the grid",
                Location = offTheGridLocation,
                StoppedOn = stoppedOn,
                Tag = offTheGridTag,
                UserId = userId
            };

            _entryRepository.Add(offTheGridEntry);
        }
Esempio n. 10
0
        public void Test_Add_Adds_And_Also_Adds_OffTheGridEntry_When_Empty_EntryRepository()
        {
            var entryRepository = new Mock<IEntryRepository>();
            var locationRepository = new Mock<ILocationRepository>();
            var tagRepository = new Mock<ITagRepository>();
            var timeLineServiceStub = new Mock<ITimelineColorService>();
            var timeServiceStub = new Mock<ITimeService>();
            var unitOfWorkStub = new Mock<IUnitOfWork>();

            timeLineServiceStub.Setup(t => t.GetRandom())
                            .Returns(new TimelineColor("#FFF"));
            entryRepository.Setup(e => e.IsEmpty(It.IsAny<string>()))
                            .Returns(true);

            var entryService = new Mock<EntryService>(
               entryRepository.Object,
               locationRepository.Object,
               tagRepository.Object,
               timeLineServiceStub.Object,
               timeServiceStub.Object,
               unitOfWorkStub.Object);

            var newEntry = new Entry()
            {
                Location = new Location() { Name = "Test_Location" },
                Tag = new EntryTag() { Name = "Test_Tag" },
                UserId = "1"
            };

            entryService.Object.AddEntry(newEntry);

            entryRepository.Verify(e => e.Add(It.IsAny<Entry>()), Times.Exactly(2));
        }
Esempio n. 11
0
        public void Test_AddEntry_Throws_ArgumentNullException_On_Null_EmptyUserId()
        {
            var newEntryWithoutUserId = new Entry() {
                Description = "Test",
                Location = new Location() { Name = "Test" },
                Tag = new EntryTag() { Name = "Test" }
            };

            SetupReallyBasicEntryService().AddEntry(newEntryWithoutUserId);
        }
Esempio n. 12
0
        public void Test_AddEntry_Does_Not_Add_Existing_Tag()
        {
            var entryRepository = new Mock<IEntryRepository>();
            var locationRepository = new Mock<ILocationRepository>();
            var tagRepository = new Mock<ITagRepository>();
            var timeLineServiceStub = new Mock<ITimelineColorService>();
            var timeServiceStub = new Mock<ITimeService>();
            var unitOfWorkStub = new Mock<IUnitOfWork>();

            entryRepository.Setup(e => e.IsEmpty(It.IsAny<string>()))
                            .Returns(false);
            tagRepository.Setup(l => l.Find(It.IsAny<string>(), It.IsAny<string>()))
                                .Returns(new EntryTag());

            var entryService = new Mock<EntryService>(
               entryRepository.Object,
               locationRepository.Object,
               tagRepository.Object,
               timeLineServiceStub.Object,
               timeServiceStub.Object,
               unitOfWorkStub.Object);

            var newEntry = new Entry()
            {
                Location = new Location() { Name = "TestLocation" },
                Tag = new EntryTag() { Name = "TestTag" },
                UserId = "1"
            };

            entryService.Object.AddEntry(newEntry);

            tagRepository.Verify(e => e.Add(It.IsAny<EntryTag>()), Times.Never());
        }