示例#1
0
        public async Task <CreateNmedianPayload> CreateNmedianAsync(
            CreateNmedianInput input,
            [Service] IDateTimeOffset dateTimeOffset,
            [Service] IGuid guid,
            [ScopedService] NmediaContext dbContext,
            CancellationToken cancellationToken
            )
        {
            var entity = new Nmedian
            {
                Age        = input.Age,
                Created    = dateTimeOffset.Now,
                IsActive   = input.IsActive,
                Hired      = input.Hired,
                HourlyRate = input.HourlyRate,
                JobTitle   = input.JobTitle,
                Name       = input.Name,
                Picture    = input.Picture,
                Slug       = input.Slug,
                Uuid       = guid.NewGuid()
            };

            dbContext.Nmedians.Add(entity);
            await dbContext.SaveChangesAsync(cancellationToken);

            return(new CreateNmedianPayload(entity));
        }
        public DeviceMonitorWithExpiry(
            [NotNull] ILogger logger,
            [NotNull] IDateTimeOffset dateTimeOffset,
            [NotNull] IDeviceMonitor deviceMonitor,
            [NotNull] ISubject <IDevice> deviceExpired,
            [NotNull] IObservableTimerFactory factory,
            [NotNull] IScheduler scheduler)
        {
            Guard.ArgumentNotNull(logger,
                                  nameof(logger));
            Guard.ArgumentNotNull(dateTimeOffset,
                                  nameof(dateTimeOffset));
            Guard.ArgumentNotNull(deviceMonitor,
                                  nameof(deviceMonitor));
            Guard.ArgumentNotNull(deviceExpired,
                                  nameof(deviceExpired));
            Guard.ArgumentNotNull(factory,
                                  nameof(factory));
            Guard.ArgumentNotNull(scheduler,
                                  nameof(scheduler));

            _logger         = logger;
            _dateTimeOffset = dateTimeOffset;
            _deviceMonitor  = deviceMonitor;
            _deviceExpired  = deviceExpired;

            _timer = factory.Create(TimeOut,
                                    scheduler)
                     .SubscribeOn(scheduler)
                     .Subscribe(CleanUp,
                                OnError,
                                OnCompleted);
        }
示例#3
0
        public void CleanUp_ForNotExpiredDeviceInCollection_DoesNotNotifyDeviceExpired(
            ILogger logger,
            IDateTimeOffset dateTimeOffset,
            IDeviceMonitor deviceMonitor,
            ISubject <IDevice> deviceExpired,
            ObservableTimerFactory factory,
            TestScheduler scheduler,
            IDevice device)
        {
            deviceMonitor.DiscoveredDevices
            .Returns(new[] { device });

            var sut = new DeviceMonitorWithExpiry(logger,
                                                  dateTimeOffset,
                                                  deviceMonitor,
                                                  deviceExpired,
                                                  factory,
                                                  scheduler);

            dateTimeOffset.Ticks
            .Returns(sut.TimeOut.Ticks);
            dateTimeOffset.Now
            .Returns(dateTimeOffset);

            device.BroadcastTime
            .Ticks
            .Returns(sut.TimeOut.Ticks / 2);

            scheduler.AdvanceBy(sut.TimeOut.Ticks);

            deviceExpired.DidNotReceive()
            .Publish(device);
        }
示例#4
0
        public void CleanUp_ForOneExpiredDeviceInCollection_RemovesDeviceFromCollection(
            ILogger logger,
            IDateTimeOffset dateTimeOffset,
            IDeviceMonitor deviceMonitor,
            ISubject <IDevice> deviceExpired,
            ObservableTimerFactory factory,
            TestScheduler scheduler,
            IDevice device)
        {
            deviceMonitor.DiscoveredDevices
            .Returns(new[] { device });

            var sut = new DeviceMonitorWithExpiry(logger,
                                                  dateTimeOffset,
                                                  deviceMonitor,
                                                  deviceExpired,
                                                  factory,
                                                  scheduler);

            dateTimeOffset.Ticks
            .Returns(sut.TimeOut.Ticks);
            dateTimeOffset.Now
            .Returns(dateTimeOffset);

            device.BroadcastTime
            .Ticks
            .Returns(0);

            scheduler.AdvanceBy(sut.TimeOut.Ticks + 1);

            deviceMonitor.Received()
            .RemoveDevice(device);
        }
示例#5
0
        public void CleanUp_ForOneExpiredDeviceInCollection_NotifiesDeviceExpired(
            ILogger logger,
            IDateTimeOffset dateTimeOffset,
            IDeviceMonitor deviceMonitor,
            Subject <IDevice> deviceExpired,
            ObservableTimerFactory factory,
            TestScheduler scheduler,
            IDevice device)
        {
            var sut = new DeviceMonitorWithExpiry(logger,
                                                  dateTimeOffset,
                                                  deviceMonitor,
                                                  deviceExpired,
                                                  factory,
                                                  scheduler);

            IDevice expiredDevice = null;

            using var disposable = sut.DeviceExpired
                                   .Subscribe(expired => expiredDevice = expired);

            deviceExpired.OnNext(device);

            scheduler.AdvanceBy(sut.TimeOut.Ticks);

            expiredDevice.Should()
            .Be(device);
        }
示例#6
0
 public void Setup()
 {
     _dateTimeOffset = A.Fake <IDateTimeOffset>();
     _fortuneCookie  = A.Fake <IFortuneCookie>();
     _console        = A.Fake <IConsole>();
     _app            = new App(_dateTimeOffset, _fortuneCookie, _console);
 }
 public AppDbContext(DbContextOptions <AppDbContext> options,
                     ICurrentUserService currentUserService,
                     IDateTimeOffset dateTimeOffset)
     : base(options)
 {
     _currentUserService = currentUserService;
     _dateTimeOffset     = dateTimeOffset;
 }
示例#8
0
        public void Initialize()
        {
            var dateTimeOffset = DateTimeOffset.Parse("2/10/2007 1:02:03 PM -7:30");

            _broadcastTime = new DateTimeOffsetWrapper(dateTimeOffset);

            _comparer = new DeviceComparer();
        }
示例#9
0
        public void Initialize()
        {
            _factory = TestFactory;

            _broadcastTime          = new DateTimeOffsetWrapper().Now;
            _address                = 254682828386071;
            _name                   = "Name";
            _rawSignalStrengthInDBm = -50;
        }
示例#10
0
 private IDevice TestFactory(IDateTimeOffset broadcastTime,
                             ulong address,
                             string name,
                             short rawSignalStrengthInDBm)
 {
     return(new Device(broadcastTime,
                       address,
                       name,
                       rawSignalStrengthInDBm));
 }
        public TestContext(ICurrentUserService currentUserService, IDateTimeOffset dateTimeOffset)
        {
            _currentUserService = currentUserService;
            _dateTimeOffset     = dateTimeOffset;
            Context             = CreateDbContext();
            InitializeDbForTests();

            // to reload cache - all tracked entities (and included) will reset
            Context = CreateDbContext();
        }
示例#12
0
        public void Constructor_ForBroadcastTimeNull_Throws()
        {
            _broadcastTime = null;

            // ReSharper disable once ObjectCreationAsStatement
            Action action = () => { CreateSut(); };

            action.Should()
            .Throw <ArgumentNullException>()
            .WithParameter("broadcastTime");
        }
示例#13
0
 public LogInHandler(
     IAuthenticationService authenticationService,
     IDateTimeOffset dateTimeOffset,
     IFakturContext dbContext,
     IGuid guid
     )
 {
     this.authenticationService = authenticationService ?? throw new ArgumentNullException(nameof(authenticationService));
     this.dateTimeOffset        = dateTimeOffset ?? throw new ArgumentNullException(nameof(dateTimeOffset));
     this.dbContext             = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     this.guid = guid ?? throw new ArgumentNullException(nameof(guid));
 }
示例#14
0
 public AuthenticationService(
     IDateTimeOffset dateTimeOffset,
     IOptions <TokenOptions> options,
     IPasswordService passwordService,
     ITokenService tokenService
     )
 {
     this.dateTimeOffset  = dateTimeOffset ?? throw new ArgumentNullException(nameof(dateTimeOffset));
     this.options         = options?.Value ?? throw new ArgumentNullException(nameof(options));
     this.passwordService = passwordService ?? throw new ArgumentNullException(nameof(passwordService));
     this.tokenService    = tokenService ?? throw new ArgumentNullException(nameof(tokenService));
 }
示例#15
0
 public ProcessReceiptHandler(
     IApplicationContext appContext,
     IDateTimeOffset dateTimeOffset,
     IFakturContext dbContext,
     IGuid guid
     )
 {
     this.appContext     = appContext ?? throw new ArgumentNullException(nameof(appContext));
     this.dateTimeOffset = dateTimeOffset ?? throw new ArgumentNullException(nameof(dateTimeOffset));
     this.dbContext      = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     this.guid           = guid ?? throw new ArgumentNullException(nameof(guid));
 }
示例#16
0
 public UpdateProductHandler(
     IApplicationContext appContext,
     IDateTimeOffset dateTimeOffset,
     IFakturContext dbContext,
     IMapper mapper
     )
 {
     this.appContext     = appContext ?? throw new ArgumentNullException(nameof(appContext));
     this.dateTimeOffset = dateTimeOffset ?? throw new ArgumentNullException(nameof(dateTimeOffset));
     this.dbContext      = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     this.mapper         = mapper ?? throw new ArgumentNullException(nameof(mapper));
 }
示例#17
0
 public ChangePasswordHandler(
     IApplicationContext appContext,
     IDateTimeOffset dateTimeOffset,
     IFakturContext dbContext,
     IPasswordService passwordService
     )
 {
     this.appContext      = appContext ?? throw new ArgumentNullException(nameof(appContext));
     this.dateTimeOffset  = dateTimeOffset ?? throw new ArgumentNullException(nameof(dateTimeOffset));
     this.dbContext       = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     this.passwordService = passwordService ?? throw new ArgumentNullException(nameof(passwordService));
 }
示例#18
0
        /// <inheritdoc />
        public IDevice Create(IDateTimeOffset broadcastTime,
                              ulong address,
                              string name,
                              short rawSignalStrengthInDBm)
        {
            Guard.ArgumentNotNull(broadcastTime,
                                  nameof(broadcastTime));

            return(_factory.Invoke(broadcastTime,
                                   address,
                                   name,
                                   rawSignalStrengthInDBm));
        }
示例#19
0
 public SaveBannerHandler(
     IApplicationContext appContext,
     IDateTimeOffset dateTimeOffset,
     IFakturContext dbContext,
     IGuid guid,
     IMapper mapper
     )
 {
     this.appContext     = appContext ?? throw new ArgumentNullException(nameof(appContext));
     this.dateTimeOffset = dateTimeOffset ?? throw new ArgumentNullException(nameof(dateTimeOffset));
     this.dbContext      = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     this.guid           = guid ?? throw new ArgumentNullException(nameof(guid));
     this.mapper         = mapper ?? throw new ArgumentNullException(nameof(mapper));
 }
示例#20
0
        public Device([NotNull] IDateTimeOffset broadcastTime,
                      ulong address,
                      [GuardIgnore] string name,
                      short rawSignalStrengthInDBm)
        {
            Guard.ArgumentNotNull(broadcastTime,
                                  nameof(broadcastTime));

            BroadcastTime          = broadcastTime;
            Address                = address;
            MacAddress             = address.ToMacAddress( );
            Name                   = name ?? string.Empty;
            RawSignalStrengthInDBm = rawSignalStrengthInDBm;
        }
 public SaveNmedianHandler(
     IApplicationContext appContext,
     IDateTimeOffset dateTimeOffset,
     INmediaContext dbContext,
     IGuid guid,
     IMapper mapper
     )
 {
     _appContext     = appContext ?? throw new ArgumentNullException(nameof(appContext));
     _dateTimeOffset = dateTimeOffset ?? throw new ArgumentNullException(nameof(dateTimeOffset));
     _dbContext      = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     _guid           = guid ?? throw new ArgumentNullException(nameof(guid));
     _mapper         = mapper ?? throw new ArgumentNullException(nameof(mapper));
 }
示例#22
0
        public void Constructor_ForDateTimeOffsetNull_Throws(
            Lazy <DeviceMonitorWithExpiry> sut,
            [BeNull] IDateTimeOffset dateTimeOffset)
        {
            // ReSharper disable once UnusedVariable
            Action action = () =>
            {
                var test = sut.Value;
            };

            action.Should()
            .Throw <ArgumentNullException>()
            .WithParameter(nameof(dateTimeOffset));
        }
示例#23
0
 public ImportReceiptHandler(
     IApplicationContext appContext,
     IDateTimeOffset dateTimeOffset,
     IFakturContext dbContext,
     IGuid guid,
     IMapper mapper,
     IReceiptParser parser,
     IOptions <TaxOptions> taxOptions
     )
 {
     this.appContext     = appContext ?? throw new ArgumentNullException(nameof(appContext));
     this.dateTimeOffset = dateTimeOffset ?? throw new ArgumentNullException(nameof(dateTimeOffset));
     this.dbContext      = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     this.guid           = guid ?? throw new ArgumentNullException(nameof(guid));
     this.mapper         = mapper ?? throw new ArgumentNullException(nameof(mapper));
     this.parser         = parser ?? throw new ArgumentNullException(nameof(parser));
     this.taxOptions     = taxOptions?.Value ?? throw new ArgumentNullException(nameof(taxOptions));
 }
示例#24
0
        public async Task <CreateArticlePayload> CreateArticleAsync(
            CreateArticleInput input,
            [Service] IDateTimeOffset dateTimeOffset,
            [Service] IGuid guid,
            [Service] ITopicEventSender sender,
            [ScopedService] NmediaContext dbContext,
            CancellationToken cancellationToken
            )
        {
            Nmedian?nmedian = null;

            if (input.NmedianId.HasValue)
            {
                nmedian = await dbContext.Nmedians.SingleOrDefaultAsync(
                    x => x.Uuid == input.NmedianId.Value,
                    cancellationToken
                    ) ?? throw new ArgumentException($"The Nmédian (ID={input.NmedianId}) could not be found.", nameof(input));
            }

            var entity = new Article
            {
                Categories = input.Categories,
                Content    = input.Content,
                Created    = dateTimeOffset.Now,
                Nmedian    = nmedian,
                NmedianId  = nmedian?.Id,
                Picture    = input.Picture,
                Published  = input.Published,
                Title      = input.Title,
                Uuid       = guid.NewGuid()
            };

            dbContext.Articles.Add(entity);
            await dbContext.SaveChangesAsync(cancellationToken);

            await sender.SendAsync(nameof(Subscription.OnArticleSaved), entity, cancellationToken);

            return(new CreateArticlePayload(entity));
        }
示例#25
0
        public async Task <UpdateArticlePayload> UpdateArticleAsync(
            UpdateArticleInput input,
            [Service] IDateTimeOffset dateTimeOffset,
            [Service] ITopicEventSender sender,
            [ScopedService] NmediaContext dbContext,
            CancellationToken cancellationToken
            )
        {
            Nmedian?nmedian = null;

            if (input.NmedianId.HasValue)
            {
                nmedian = await dbContext.Nmedians.SingleOrDefaultAsync(
                    x => x.Uuid == input.NmedianId.Value,
                    cancellationToken
                    ) ?? throw new ArgumentException($"The Nmédian (ID={input.NmedianId}) could not be found.", nameof(input));
            }

            Article entity = await dbContext.Articles
                             .SingleOrDefaultAsync(x => x.Uuid == input.Id, cancellationToken)
                             ?? throw new ArgumentException($"The Article (ID={input.Id}) could not be found.", nameof(input));

            entity.Categories = input.Categories;
            entity.Content    = input.Content;
            entity.Nmedian    = nmedian;
            entity.NmedianId  = nmedian?.Id;
            entity.Picture    = input.Picture;
            entity.Published  = input.Published;
            entity.Title      = input.Title;
            entity.Updated    = dateTimeOffset.Now;

            await dbContext.SaveChangesAsync(cancellationToken);

            await sender.SendAsync(nameof(Subscription.OnArticleSaved), entity, cancellationToken);

            return(new UpdateArticlePayload(entity));
        }
示例#26
0
        public void OnError_ForInvoked_CallsStop(
            ILogger logger,
            IDateTimeOffset dateTimeOffset,
            IDeviceMonitor deviceMonitor,
            ISubject <IDevice> deviceExpired,
            IObservableTimerFactory factory,
            TestScheduler scheduler)
        {
            factory.Create(Arg.Any <TimeSpan>(),
                           Arg.Any <IScheduler>())
            .Returns(Observable.Throw <long>(new Exception()));

            var sut = new DeviceMonitorWithExpiry(logger,
                                                  dateTimeOffset,
                                                  deviceMonitor,
                                                  deviceExpired,
                                                  factory,
                                                  scheduler);

            scheduler.AdvanceBy(sut.TimeOut.Ticks);

            deviceMonitor.Received()
            .Stop();
        }
示例#27
0
 public PersonFactory(IDateTimeOffset dateTimeOffset)
 {
     _dateTimeOffset = dateTimeOffset;
 }
示例#28
0
 public FortuneCookie(IDateTimeOffset dateTimeOffset)
 {
     _dateTimeOffset = dateTimeOffset;
 }
 public FortuneCookie(IDateTimeOffset dateTimeOffset)
 {
     _now = dateTimeOffset.UtcNow;
 }
示例#30
0
        public CreatePostCommandHandler(BlogSiteDBContext context, IDateTimeOffset dateTimeOffset)
        {
            _Context = context ?? throw new ArgumentNullException(nameof(context));

            _DateTimeOffset = dateTimeOffset ?? throw new ArgumentNullException(nameof(dateTimeOffset));
        }