Esempio n. 1
0
        public async Task Delete_HasNotActiveRents_ShouldDelete()
        {
            var oldCount   = Subscribers.Count;
            var subscriber = Subscribers.First();

            if (!subscriber.Rents.Any())
            {
                subscriber.Rents.Add(new Rent(null, null)
                {
                    IsActive = false
                });
            }
            var returnVal = await SubscribersService.Delete(subscriber.Id);

            #region Assert returnVal

            Assert.That(returnVal.Lastname, Is.EqualTo(subscriber.Lastname));
            Assert.That(returnVal.Firstname, Is.EqualTo(subscriber.Firstname));
            Assert.That(returnVal.Middlename, Is.EqualTo(subscriber.Middlename));
            Assert.That(returnVal.IsDeleted, Is.True);
            #endregion

            Assert.That(Subscribers.Count, Is.EqualTo(oldCount));

            var deletedSubscriber = Subscribers.SingleOrDefault(x => x.Id == subscriber.Id);
            Assert.That(deletedSubscriber, Is.Not.Null);
            Assert.That(deletedSubscriber.IsDeleted, Is.True);
        }
Esempio n. 2
0
        public void Delete_HasRents_ShouldThrowInvalidCountException()
        {
            var first        = Invoices.First();
            var incomingBook = first.IncomingBooks.First();

            Rents.Add(new Rent(incomingBook.Book, Subscribers.First(), Books.Single(x => x.Id == incomingBook.Book.Id).Count)
            {
                Id = _random.Next(int.MaxValue)
            });

            Assert.Throws <InvoiceCountException>(async() => await InvoicesService.Delete(first.Id));
        }
Esempio n. 3
0
        public void Delete_ShouldThrownSubscriberHasActiveRentsException()
        {
            var subscriber = Subscribers.First();

            if (!subscriber.Rents.Any())
            {
                subscriber.Rents.Add(new Rent(null, null)
                {
                    IsActive = true
                });
            }
            Assert.Throws <SubscriberHasActiveRentsException>(async() => await SubscribersService.Delete(subscriber.Id));
        }
Esempio n. 4
0
        public async Task SubscribeAsync(IMqttSubscriber subscriber, string topic, MqttQualityOfServiceLevel mqttQosLevel)
        {
            if (!Subscribers.Any(e => e.Key == topic))
            {
                Subscribers.Add(new KeyValuePair <string, List <IMqttSubscriber> >(topic, new List <IMqttSubscriber>()));
            }

            var topicSubscribers = Subscribers.First(e => e.Key == topic).Value;

            // client already subscribed to this topic
            if (!topicSubscribers.Contains(subscriber))
            {
                await MqttClient.SubscribeAsync(topic, mqttQosLevel);

                topicSubscribers.Add(subscriber);
            }
        }
Esempio n. 5
0
        public void Create_BookNotHasAvailableCount_ShouldThrownBookNotHasAvailableCountException()
        {
            var book     = Books.First();
            var reserved = Rents.Where(x => x.Book.Id == book.Id).Sum(x => x.Count);

            Rents.Add(new Rent(book, Subscribers.First(), book.Count - reserved)
            {
                Id   = Random.Next(int.MaxValue),
                Date = DateTime.Now,
            });

            var dto = new RentDto()
            {
                Subscriber = Mapper.Map <SubscriberDto>(Subscribers.First()),
                Book       = Mapper.Map <BookDto>(book),
                Count      = 1,
                Date       = DateTime.Now,
            };

            Assert.Throws <NotHasAvailableBooksCountException>(async() => await RentsService.Create(dto));
        }
Esempio n. 6
0
        public async Task Delete_ShouldDeleted()
        {
            var oldCount = Subscribers.Count;

            var subscriber = Subscribers.First();

            subscriber.Rents.Clear();


            var returnVal = await SubscribersService.Delete(subscriber.Id);

            #region Assert returnVal

            Assert.That(returnVal.Lastname, Is.EqualTo(subscriber.Lastname));
            Assert.That(returnVal.Firstname, Is.EqualTo(subscriber.Firstname));
            Assert.That(returnVal.Middlename, Is.EqualTo(subscriber.Middlename));

            #endregion

            Assert.That(Subscribers.Count, Is.EqualTo(oldCount - 1));
            Assert.That(Subscribers.SingleOrDefault(x => x.Id == subscriber.Id), Is.Null);
        }